开发者

Toggle JToggleButton without clicking it, and unsetting styles

开发者 https://www.devze.com 2023-01-26 09:01 出处:网络
I have a few toggle buttons to add styling to text in the form of: 开发者_运维知识库JToggleButton boldButton = new JToggleButton(\"Bold\");

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


boldButton.setSelected(false)

should be all you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消