java - JComboBox inside a Border causes IllegalComponentStateException -
i found useful code create titled border contains component title santhosh kumar t: componenttitledborder. employed using check box, when decided use combo box, shows text part of combo box not drop down button:
when click on combo box following exception:
exception in thread "awt-eventqueue-0" java.awt.illegalcomponentstateexception: component must showing on screen determine location @ java.awt.component.getlocationonscreen_notreelock(unknown source) @ java.awt.component.getlocationonscreen(unknown source) @ javax.swing.jpopupmenu.show(unknown source) @ javax.swing.plaf.basic.basiccombopopup.show(unknown source) @ javax.swing.plaf.basic.basiccombopopup.togglepopup(unknown source) @ javax.swing.plaf.basic.basiccombopopup$handler.mousepressed(unknown source) @ java.awt.component.processmouseevent(unknown source) @ javax.swing.jcomponent.processmouseevent(unknown source) @ java.awt.component.processevent(unknown source) @ java.awt.container.processevent(unknown source) @ java.awt.component.dispatcheventimpl(unknown source) @ java.awt.container.dispatcheventimpl(unknown source) @ java.awt.component.dispatchevent(unknown source) @ test.componenttitledborder.dispatchevent(componenttitledborder.java:74) @ test.componenttitledborder.mousepressed(componenttitledborder.java:96) @ java.awt.component.processmouseevent(unknown source) @ javax.swing.jcomponent.processmouseevent(unknown source) @ java.awt.component.processevent(unknown source) @ java.awt.container.processevent(unknown source) @ java.awt.component.dispatcheventimpl(unknown source) @ java.awt.container.dispatcheventimpl(unknown source) @ java.awt.component.dispatchevent(unknown source) @ java.awt.lightweightdispatcher.retargetmouseevent(unknown source) @ java.awt.lightweightdispatcher.processmouseevent(unknown source) @ java.awt.lightweightdispatcher.dispatchevent(unknown source) @ java.awt.container.dispatcheventimpl(unknown source) @ java.awt.window.dispatcheventimpl(unknown source) @ java.awt.component.dispatchevent(unknown source) @ java.awt.eventqueue.dispatcheventimpl(unknown source) @ java.awt.eventqueue.access$200(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.awt.eventqueue$4.run(unknown source) @ java.awt.eventqueue$4.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.awt.eventqueue.dispatchevent(unknown source) @ java.awt.eventdispatchthread.pumponeeventforfilters(unknown source) @ java.awt.eventdispatchthread.pumpeventsforfilter(unknown source) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.run(unknown source)
i have looked @ google results find exception, none of them helped me understand specific problem. illustrate, provide sscce:
package test; import java.awt.borderlayout; import java.awt.dimension; import javax.swing.defaultcomboboxmodel; import javax.swing.jcombobox; import javax.swing.jcomponent; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.swingutilities; import javax.swing.uimanager; @suppresswarnings("serial") public class problem extends jcomponent { jpanel area = new jpanel(); jcombobox<string> cb; public problem() { area.setpreferredsize(new dimension(100,100)); string[] options = {"one", "two"}; cb = new jcombobox<string>(new defaultcomboboxmodel<string>(options)); cb.seteditable(false); cb.setselectedindex(0); this.setlayout(new borderlayout()); area.setborder(new componenttitledborder(cb, area, uimanager.getborder("titledborder.border"))); this.add(area, borderlayout.center); } public static void main(string[] args) { swingutilities.invokelater(new runnable() { @override public void run() { jframe frame = new jframe(); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.add(new problem()); frame.pack(); frame.setvisible(true); } }); } }
please me fix , understand nature of error.
define jpanel
borderlayout
, add jcombobox
panel. assign componenttitledborder
panel rather jcombobox
directly.
update:
jpanel p = new jpanel(); p.setlayout(new borderlayout()); p.add(cb, borderlayout.center); area.setborder(new componenttitledborder(p, area, uimanager.getborder("titledborder.border")));
Comments
Post a Comment