How do I get the boolean value of the JCheckBoxMenuItem?

I have JCheckBoxMenuItem as a field:

private JCheckBoxMenuItem chckbxmntmDisableSending = new JCheckBoxMenuItem("Disable Sending");

      

I need to figure out if it's checked or not, some time later, when you do something else (clicking the submit button basically). How do I get the meaning of this?

I checked the value JCheckBoxMenuItem ',' get boolean JCheckBoxMenuItem ', others. I've also looked at the documentation that talks about getState()

, but I get the impression that getState()

it only gives you whether it's mouse-selected or not.

How to get the current boolean value of a JCheckbox menu item? That is, is it verified or not?

+3


source to share


2 answers


According to the Javadocs, the method isSelected()

also returns a boolean value for its state.



+1


source


Straight from the JCheckBoxMenu Javadoc

Either SelectSlect / SetSelected or getState / setState can be used to determine / set the state of the menu item selection. The preferred ones are SelectSelected and SetSelected, which work for all menus and buttons. The getState and setState methods exist for compatibility with other component sets.



To detect when it will change state, add an ItemListener to your JCheckBoxMenuItem via addItemListener .

+2


source







All Articles