私は異なるサイズの2つのjbuttonを持っています。私はより大きなサイズの他のjbuttonよりも小さいjbuttonを配置しました。また、マウスのOnClickで何らかのアクションを実行しているより大きなサイズのjbuttonにMouseListenerを追加しました。別のjbutton上に配置されたjbuttonにフォーカスする方法は?
問題は、マウスがより小さなサイズのjbuttonからもっと小さなサイズのjbuttonに変更したい場合です。
小さいサイズのjボタンをクリックしても何も処理は行われません。
誰でもこの問題を解決できる方法を教えていただけますか?
コードスニペット:あなたのコード例で
CustomButtom button1 = new CustomButton(icon, null, null);
CustomButton button2 = new CustomButton(icon1, iconRollover, iconPressed);
button1.setBounds(new Rectangle(542,14,115,86));
button2.setBounds(new Rectangle(634,79,24,22));
button1.addMouseListener(new MouseListener(){
@Override
public void mouseClicked(){
performing some task
}
//rest of the methods are same.
});
class CustomButton extends JButton()
{
public CustomButton(Icon icon, Icon rollover, Icon pressed)
{
super(icon);
setRolloverEnabled(false);
setRolloverIcon(rollover);
setPressedIcon(pressed);
setContentAreaFilled(false);
}
}
おかげ ジョティ
こんにちはJyoti、問題を示す簡単な自己完結型のコード例を投稿してください。 –
こんにちはスティーブ、私はコードスニペットを入れました。何かお勧めします。 – Jyoti
シンプルで自己完結型のコード例http://sscce.org/は、より良いガイダンスを得る可能性が高いです。また、ボタンが重なっている理由を説明するのにも役立ちます。 – trashgod