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
:
i want output this:
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
Post a Comment