Mene
Mene

Reputation: 3799

JToggleButton HideActionText hides Button-Text

I have created a JToggleButton with the Netbeans editor, setHideActionText to True and added an Action. However, the Button displays without text at all, all I see is a small square (like a checkbox). The Text of the Button is set to "b" and the Action used is StyledEditorKit.BoldAction and I haven't set any Icon.

If I don't add the Action it's working fine. Is this a bug or am I missing something (probably very stupid)?

Maybe more clearly:

I want the button to show the text that I set with setText, not the one I set with Action.putValue(Action.NAME, "Some Name") and I don't want to display an Icon.

Upvotes: 1

Views: 1042

Answers (1)

kleopatra
kleopatra

Reputation: 51525

That's the expected behaviour, as documented in the api of setHideTextAction (why-o-why don't you read the javadoc, it's there for a reason):

 * 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.
 *

don't touch the property and be happy ;-)

Edit: seeing more clearly now - thanks for the clarification

  • if true, the button's text property is not touched when the action's name property is changed
  • undocumented: setting it to true, nulls the button's text property

To have a "sticky" (button defined only) text property, sequence of method calls matters (which shouldn't be case .. but then ..) First that hideText

button.setHideActionText(true);
button.setText("myText");

Upvotes: 1

Related Questions