这已经困扰我一段时间了。如果我定义setText
在 JButton 上before定义setAction
,文本消失:
JButton test = new JButton();
test.setText("test"); // Before - disappears!
test.setAction(new AbstractAction() {
public void actionPerformed(ActionEvent e) {
// do something
}
});
this.add(test);
If it's after, 没问题。
JButton test = new JButton();
test.setAction(new AbstractAction() {
public void actionPerformed(ActionEvent e) {
// do something
}
});
test.setText("test"); // After - no problem!
this.add(test);
此外,如果我在 JButton 构造函数中设置文本,那就没问题了!啊啊!
为什么会出现这种情况?
如中所述文档 http://Setting%20the%20Action%20results%20in%20immediately%20changing%20all%20the%20properties%20described%20in%20Swing%20Components%20Supporting%20Action.:
设置操作会立即更改所有属性
Swing 组件支持操作中描述。
这些属性被描述here http://docs.oracle.com/javase/6/docs/api/javax/swing/Action.html#buttonActions,并包含文本。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)