1
我有兩個不同大小的jbuttons。我把更小的jbutton放在了更大尺寸的其他jbutton上。我還將MouseListener添加到對鼠標OnClick執行某些操作的較大大小的jbutton中。如何關注jbutton放在另一個jbutton上?
的問題是,我想鼠標的控制,從更大尺寸的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);
}
}
感謝 喬蒂
喬蒂嗨,你能請張貼演示該問題的簡單自包含的代碼示例? – 2010-11-23 11:06:50
嗨史蒂夫,我已經把代碼片段。請提出建議。 – Jyoti 2010-11-23 11:35:21