java - Problems with Changing JTextArea font size -
i trying prompt user input joptionpane change font size of jtextarea, shown below as, "console".
issue:
however, joptionpane not showing when click on size jmenu item.
code:
font font = new font("arial", font.plain, 12); panel = new jpanel(); panel.setlayout(new borderlayout()); add(panel, borderlayout.center); jtextarea console = new jtextarea(); console.setlinewrap(true); console.setwrapstyleword(true); console.seteditable(false); console.setfont(font); jscrollpane scroll = new jscrollpane(console); scroll.setverticalscrollbarpolicy(scrollpaneconstants.vertical_scrollbar_always); panel.add(scroll, borderlayout.center); jmenubar bar = new jmenubar(); panel.add(bar, borderlayout.north); jmenu size = new jmenu("size"); size.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent e) { string fontsize = joptionpane.showinputdialog(panel, "new font size, 6 or larger:", "set font size", joptionpane.ok_cancel_option); font newfont = font.derivefont(integer.parseint(fontsize)); console.setfont(newfont); } }); bar.add(size);
this seems bug use ´menulistener´ described in answer @tpete
here code provided in answer work around issue:
jmenu menu = new jmenu("mymenu"); menu.addmenulistener(new menulistener() { @override public void menuselected(menuevent e) { system.out.println("menuselected"); } @override public void menudeselected(menuevent e) { system.out.println("menudeselected"); } @override public void menucanceled(menuevent e) { system.out.println("menucanceled"); } });
basically he's using menulistener
instead of actionlistener
catch event successfully.
hope helps!
Comments
Post a Comment