[英]how to focus on jbutton placed over another jbutton?
我有兩個不同大小的jbutton。 我將較小的jbutton放置在其他較大的jbutton上。 我還將MouseListener添加到了較大的jbutton上,該按鈕在鼠標OnClick上執行一些操作。
問題是,當鼠標移到較小尺寸的jbutton上時,我想將鼠標的控制從較大尺寸的jbutton更改為較小尺寸的jbutton,這目前沒有發生。
當我單擊較小尺寸的jbutton時,不執行任何操作。
誰能告訴我如何解決這個問題。
程式碼片段:
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
在示例代碼中,您永遠不會將偵聽器添加到Button2,因此它將永遠不會獲得鼠標事件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.