Error : IllegalComponentStateException when pressing JMenuItem in java swing (OSX) -


during project stumbled upon confusing error message shows when clicking of projects' jmenuitems. program continue function error log gets messy. have found out same program not give error messages when running windows (via vm on macbook). tried building extremely simplified version showing jmenuitem error message still appears.

this dumbed down jmenuitem test program wrote:

import javax.swing.jframe; import javax.swing.jmenu; import javax.swing.jmenubar; import javax.swing.jmenuitem; public class testbug { public static jmenuitem menuitem;   public static void main(string args[]){     jframe frame = new jframe("java praktikum");     frame.setdefaultcloseoperation(jframe.exit_on_close);     frame.setlocation(100,100);     frame.setsize(800, 600);      jmenubar menubar = new jmenubar();     jmenu testmenu = new jmenu();     menuitem = new jmenuitem("testmenuitem");      testmenu.add(menuitem);     menubar.add(testmenu);     frame.setjmenubar(menubar);      frame.pack();     frame.setvisible(true);  }} 

and error message showing everytime press jmenuitem:

java.awt.illegalcomponentstateexception: component must showing on screen determine location @ java.awt.component.getlocationonscreen_notreelock(component.java:2044) @ java.awt.component.getlocationonscreen(component.java:2018) @ sun.lwawt.macosx.caccessibility$22.call(caccessibility.java:390) @ sun.lwawt.macosx.caccessibility$22.call(caccessibility.java:388) @ sun.lwawt.macosx.lwctoolkit$callablewrapper.run(lwctoolkit.java:504) @ java.awt.event.invocationevent.dispatch(invocationevent.java:251) @ sun.lwawt.macosx.lwctoolkit$4.dispatch(lwctoolkit.java:529) @ java.awt.eventqueue.dispatcheventimpl(eventqueue.java:733) @ java.awt.eventqueue.access$200(eventqueue.java:103) @ java.awt.eventqueue$3.run(eventqueue.java:694) @ java.awt.eventqueue$3.run(eventqueue.java:692) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(protectiondomain.java:76) @ java.security.protectiondomain$1.dointersectionprivilege(protectiondomain.java:87) @ java.awt.eventqueue$4.run(eventqueue.java:708) @ java.awt.eventqueue$4.run(eventqueue.java:706) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(protectiondomain.java:76) @ java.awt.eventqueue.dispatchevent(eventqueue.java:705) @ java.awt.eventdispatchthread.pumponeeventforfilters(eventdispatchthread.java:242) @ java.awt.eventdispatchthread.pumpeventsforfilter(eventdispatchthread.java:161) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(eventdispatchthread.java:150) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:146) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:138) @ java.awt.eventdispatchthread.run(eventdispatchthread.java:91) 

theres lines macosx in there google has not helped me.

thanks in forward! <3

the following variation of program works me on mac os x 10.9 java 8. note swing gui objects should constructed , manipulated only on event dispatch thread.

image

import java.awt.eventqueue; import javax.swing.jframe; import javax.swing.jmenu; import javax.swing.jmenubar; import javax.swing.jmenuitem;  public class testbug {  public static jmenuitem menuitem;       public static void main(string args[]) {         eventqueue.invokelater(new runnable() {             public void run() {                 jframe frame = new jframe("java praktikum");                 frame.setdefaultcloseoperation(jframe.exit_on_close);                 jmenubar menubar = new jmenubar();                 jmenu testmenu = new jmenu("testmenu");                 menuitem = new jmenuitem("menuitem");                 testmenu.add(menuitem);                 menubar.add(testmenu);                 frame.setjmenubar(menubar);                 frame.pack();                 frame.setvisible(true);              }         });     } } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -