java - How do I place two JMenuItems adjacent to each other? -


my code:

jmenubar bar = new jmenubar(); jmenu menu = new jmenu("edit circle"); jmenuitem = new jmenuitem("help"); jmenuitem exit = new jmenuitem("exit");  bar.add(menu); bar.add(help); bar.add(exit); 

output of jmenubar:

output

i want output this:

expected_output

what need in order expected output?

you cannot add jmenuitem in jmenubar. try this.. it'll work..

    jmenubar bar = new jmenubar();     jmenu menu1 = new jmenu("edit circle");     jmenu = new jmenu("help");     jmenu exit = new jmenu("exit");     bar.add(menu1);     bar.add(help);     bar.add(exit);     exit.addmenulistener(new menulistener() {          @override         public void menuselected(menuevent e) {             system.out.println("exiting");         }          @override         public void menudeselected(menuevent e) {         }          @override         public void menucanceled(menuevent e) {         }     }); 

you cannot add actionlistener jmenu. use menulistener..

reference this...


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -