Java CheckboxMenuItem get/setState

久未见 提交于 2019-12-12 02:16:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!