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