Samsquanch
Samsquanch

Reputation: 9146

Toggle JToggleButton without clicking it, and unsetting styles

I have a few toggle buttons to add styling to text in the form of:

    JToggleButton boldButton = new JToggleButton("Bold");
    boldButton.addActionListener(new StyledEditorKit.BoldAction());
    boldButton.setFocusable(false);

and I also have various styling functions (color, left/right/center align, etc.). What I'm wanting to do is when I call a function (in this case, I'm wanting to basically make a new document) the toggle button is toggled to the off state, and all styling returns to default.

Currently I just set the frame name to untitled (previously the name of the document I was working with), and set the pane text to "", but this keeps all of the styling I had set in the previous document. Is there a better way to do it?

Thanks

Upvotes: 2

Views: 1827

Answers (1)

Starchy
Starchy

Reputation: 93

boldButton.setSelected(false)

should be all you need.

Upvotes: 4

Related Questions