问题
I am using this to create a quick menu in my Java system tray app.
Menu notiSET = new Menu("Benachrichtigungen");
CheckboxMenuItem ns1 = new CheckboxMenuItem("On");
CheckboxMenuItem ns2 = new CheckboxMenuItem("Off");
I would like to set Checkbox ns1
to true
by default.
Using ns1.setState(true);
doesnt work - I can only change the state by clicking it.
I tried using .setSelected();
or isSelected();
which doesnt work as well (methods not known).
What am I doing wrong?
回答1:
Your menu items live together within that menu.
So: don't tell a single item that it should be selected; instead turn to that menu group and tell that object which of its entries should be the default.
来源:https://stackoverflow.com/questions/42762495/java-checkboxmenuitem-get-setstate