我已经使用Netbeans编辑器setHideActionText to True创建了一个JToggleButton,并添加了一个操作。但是,Button显示时根本没有文本,我看到的只是一个小方块(就像一个复选框)。按钮的文本被设置为"b“,使用的操作是StyledEditorKit.BoldAction,而我没有设置任何图标。
如果我不添加Action,它工作得很好。这是一个bug,还是我遗漏了什么(可能非常愚蠢)?
也许更清楚的是:
我想让按钮显示我用setText设置的文本,而不是我用Action.putValue(Action.NAME, "Some Name")设置的文本,而且我不想显示图标。
发布于 2011-05-05 07:59:10
这就是预期的行为,就像setHideTextAction的api中记录的那样(为什么-o-为什么你不去读javadoc,它的存在是有原因的):
* Sets the <code>hideActionText</code> property, which determines
* whether the button displays text from the <code>Action</code>.
* This is useful only if an <code>Action</code> has been
* installed on the button.
*不要触摸财物并保持快乐;-)
编辑:现在看得更清楚了-谢谢你的澄清
为了拥有一个"sticky“(按钮定义的)文本属性,方法调用的顺序很重要(这不应该是大小写的。但是,然后..)首先是hideText
button.setHideActionText(true);
button.setText("myText");https://stackoverflow.com/questions/5891116
复制相似问题