0

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.

enter image description here

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?

Piotr Rogowski
  • 3,642
  • 19
  • 24
piguy
  • 516
  • 3
  • 10
  • 30
  • Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT components in favor of Swing. – Andrew Thompson Mar 13 '17 at 22:40
  • @AndrewThompson thank you for the hint - it is for final exam and asked to use it this way – piguy Mar 14 '17 at 14:30

1 Answers1

0

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.

GhostCat
  • 137,827
  • 25
  • 176
  • 248