swing - JAVA using JFXPanel in JFrame with mouse listener -
currently having issue cannot jframe , associated jfxpanel pop up/display. have looked @ numerous other examples on site , others of using jfxpanels jframes quite different mine. believe issue may lie in fact using 2 consecutive runnables maybe javafx thread hasnt finished time swing thread tries use components it? appreciated- relevant code below:
note: not receiving compilation or runtime errors. issue nothing happens when dialog pop
@override protected void onmousedown(mousebutton button, keymodifier keymodifier, int mousex, int mousey) { try { if (mousebutton.left.equals(button)) { featurewrapper closeststationorspanfw = selectionutil.getclosestspanorstation(tomappoint(mousex, mousey)); if (closeststationorspanfw != null) { igeometry shape = closeststationorspanfw.getifeature().getshapecopy(); if (shape instanceof point) { final point point = (point) shape; geometryutil.projectlatlong(point); final jfxpanel panel = new jfxpanel(); platform.runlater(new runnable() { @override public void run() { webview webview = new webview(); webview.getengine().setjavascriptenabled(true); try { webview.getengine().load( "http://arcgissrv:35200/woviewer/streetview/streetview.html?y=" + point.gety() + "&x=" + point .getx()); } catch (ioexception e) { e.printstacktrace(); } scene scene = new scene(webview); panel.setscene(scene); } }); swingutilities.invokelater(new runnable() { public void run() { jframe frame = new jframe(); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.getcontentpane().add(panel); frame.pack(); frame.setvisible(true); } }); .........
stacktrace error received when using suggested solution below:
edt violation detected javax.swing.jpanel[,0,0,0x0,invalid,layout=java.awt.flowlayout,alignmentx=0.0,alignmenty=0.0,border=javax.swing.plaf.synth.synthborder@a230a7,flags=9,maximumsize=,minimumsize=,preferredsize=] @ java.lang.thread.getstacktrace(thread.java:1589) @ cc.nisc.gui.checkthreadviolationrepaintmanager.checkthreadviolations(checkthreadviolationrepaintmanager.java:75) @ cc.nisc.gui.checkthreadviolationrepaintmanager.adddirtyregion(checkthreadviolationrepaintmanager.java:66) @ javax.swing.jcomponent.repaint(jcomponent.java:4793) @ java.awt.component.repaint(component.java:3297) @ javax.swing.jcomponent.setborder(jcomponent.java:1800) @ javax.swing.plaf.synth.synthstyle.installdefaults(synthstyle.java:913) @ javax.swing.plaf.synth.synthlookandfeel.updatestyle(synthlookandfeel.java:265) @ javax.swing.plaf.synth.synthpanelui.updatestyle(synthpanelui.java:117) @ javax.swing.plaf.synth.synthpanelui.installdefaults(synthpanelui.java:100) @ javax.swing.plaf.basic.basicpanelui.installui(basicpanelui.java:56) @ javax.swing.plaf.synth.synthpanelui.installui(synthpanelui.java:62) @ javax.swing.jcomponent.setui(jcomponent.java:664) @ javax.swing.jpanel.setui(jpanel.java:153) @ javax.swing.jpanel.updateui(jpanel.java:126) @ javax.swing.jpanel.<init>(jpanel.java:86) @ javax.swing.jpanel.<init>(jpanel.java:109) @ javax.swing.jpanel.<init>(jpanel.java:117) @ javax.swing.jrootpane.createglasspane(jrootpane.java:545) @ javax.swing.jrootpane.<init>(jrootpane.java:365) @ javax.swing.jframe.createrootpane(jframe.java:277) @ javax.swing.jframe.frameinit(jframe.java:258) @ javax.swing.jframe.<init>(jframe.java:181) @ cc.nisc.mapping.controls.tools.fxbrowser.<init>(fxbrowser.java:36) @ cc.nisc.mapping.controls.tools.fxbrowser.showbrowser(fxbrowser.java:22) @ cc.nisc.mapping.controls.tools.streetviewtool.onmousedown(streetviewtool.java:99) @ cc.nisc.mapping.esri.controls.core.nisctool.onmousedown(nisctool.java:135) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ com.esri.arcgis.interop.objectproxy.a(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.invoke(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.handlevtblinvokecallbacknative(native method) @ com.esri.arcgis.interop.nativeobjectproxy$0.run(unknown source) @ com.esri.arcgis.interop.stathread.b(unknown source) @ com.esri.arcgis.interop.stathread.a(unknown source) @ com.esri.arcgis.interop.stathread.post(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.a(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.executevtblcallback(unknown source) @ com.esri.arcgis.interop.nativeobjref.runmessagepump(native method) @ com.esri.arcgis.interop.stathread.run(unknown source) @ java.lang.thread.run(thread.java:745) edt violation detected javax.swing.jpanel[,0,0,0x0,invalid,layout=java.awt.flowlayout,alignmentx=0.0,alignmenty=0.0,border=javax.swing.plaf.synth.synthborder@dd79e7,flags=9,maximumsize=,minimumsize=,preferredsize=] @ java.lang.thread.getstacktrace(thread.java:1589) @ cc.nisc.gui.checkthreadviolationrepaintmanager.checkthreadviolations(checkthreadviolationrepaintmanager.java:75) @ cc.nisc.gui.checkthreadviolationrepaintmanager.adddirtyregion(checkthreadviolationrepaintmanager.java:66) @ javax.swing.jcomponent.repaint(jcomponent.java:4793) @ java.awt.component.repaint(component.java:3297) @ javax.swing.jcomponent.setborder(jcomponent.java:1800) @ javax.swing.plaf.synth.synthstyle.installdefaults(synthstyle.java:913) @ javax.swing.plaf.synth.synthlookandfeel.updatestyle(synthlookandfeel.java:265) @ javax.swing.plaf.synth.synthpanelui.updatestyle(synthpanelui.java:117) @ javax.swing.plaf.synth.synthpanelui.installdefaults(synthpanelui.java:100) @ javax.swing.plaf.basic.basicpanelui.installui(basicpanelui.java:56) @ javax.swing.plaf.synth.synthpanelui.installui(synthpanelui.java:62) @ javax.swing.jcomponent.setui(jcomponent.java:664) @ javax.swing.jpanel.setui(jpanel.java:153) @ javax.swing.jpanel.updateui(jpanel.java:126) @ javax.swing.jpanel.<init>(jpanel.java:86) @ javax.swing.jpanel.<init>(jpanel.java:109) @ javax.swing.jpanel.<init>(jpanel.java:117) @ javax.swing.jrootpane.createcontentpane(jrootpane.java:520) @ javax.swing.jrootpane.<init>(jrootpane.java:367) @ javax.swing.jframe.createrootpane(jframe.java:277) @ javax.swing.jframe.frameinit(jframe.java:258) @ javax.swing.jframe.<init>(jframe.java:181) @ cc.nisc.mapping.controls.tools.fxbrowser.<init>(fxbrowser.java:36) @ cc.nisc.mapping.controls.tools.fxbrowser.showbrowser(fxbrowser.java:22) @ cc.nisc.mapping.controls.tools.streetviewtool.onmousedown(streetviewtool.java:99) @ cc.nisc.mapping.esri.controls.core.nisctool.onmousedown(nisctool.java:135) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ com.esri.arcgis.interop.objectproxy.a(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.invoke(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.handlevtblinvokecallbacknative(native method) @ com.esri.arcgis.interop.nativeobjectproxy$0.run(unknown source) @ com.esri.arcgis.interop.stathread.b(unknown source) @ com.esri.arcgis.interop.stathread.a(unknown source) @ com.esri.arcgis.interop.stathread.post(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.a(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.executevtblcallback(unknown source) @ com.esri.arcgis.interop.nativeobjref.runmessagepump(native method) @ com.esri.arcgis.interop.stathread.run(unknown source) @ java.lang.thread.run(thread.java:745) edt violation detected javax.swing.jlayeredpane[null.layeredpane,0,0,0x0,invalid,alignmentx=0.0,alignmenty=0.0,border=,flags=0,maximumsize=,minimumsize=,preferredsize=,optimizeddrawingpossible=true] @ java.lang.thread.getstacktrace(thread.java:1589) @ cc.nisc.gui.checkthreadviolationrepaintmanager.checkthreadviolations(checkthreadviolationrepaintmanager.java:75) @ cc.nisc.gui.checkthreadviolationrepaintmanager.adddirtyregion(checkthreadviolationrepaintmanager.java:66) @ javax.swing.jcomponent.repaint(jcomponent.java:4793) @ javax.swing.jcomponent.repaint(jcomponent.java:4808) @ javax.swing.jlayeredpane.setlayer(jlayeredpane.java:374) @ javax.swing.jlayeredpane.setlayer(jlayeredpane.java:345) @ javax.swing.jlayeredpane.addimpl(jlayeredpane.java:225) @ java.awt.container.add(container.java:966) @ javax.swing.jrootpane.setcontentpane(jrootpane.java:625) @ javax.swing.jrootpane.<init>(jrootpane.java:367) @ javax.swing.jframe.createrootpane(jframe.java:277) @ javax.swing.jframe.frameinit(jframe.java:258) @ javax.swing.jframe.<init>(jframe.java:181) @ cc.nisc.mapping.controls.tools.fxbrowser.<init>(fxbrowser.java:36) @ cc.nisc.mapping.controls.tools.fxbrowser.showbrowser(fxbrowser.java:22) @ cc.nisc.mapping.controls.tools.streetviewtool.onmousedown(streetviewtool.java:99) @ cc.nisc.mapping.esri.controls.core.nisctool.onmousedown(nisctool.java:135) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ com.esri.arcgis.interop.objectproxy.a(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.invoke(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.handlevtblinvokecallbacknative(native method) @ com.esri.arcgis.interop.nativeobjectproxy$0.run(unknown source) @ com.esri.arcgis.interop.stathread.b(unknown source) @ com.esri.arcgis.interop.stathread.a(unknown source) @ com.esri.arcgis.interop.stathread.post(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.a(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.executevtblcallback(unknown source) @ com.esri.arcgis.interop.nativeobjref.runmessagepump(native method) @ com.esri.arcgis.interop.stathread.run(unknown source) @ java.lang.thread.run(thread.java:745) edt violation detected javax.swing.jpanel[null.contentpane,0,0,0x0,invalid,layout=javax.swing.jrootpane$1,alignmentx=0.0,alignmenty=0.0,border=javax.swing.plaf.synth.synthborder@dd79e7,flags=1,maximumsize=,minimumsize=,preferredsize=] @ java.lang.thread.getstacktrace(thread.java:1589) @ cc.nisc.gui.checkthreadviolationrepaintmanager.checkthreadviolations(checkthreadviolationrepaintmanager.java:75) @ cc.nisc.gui.checkthreadviolationrepaintmanager.adddirtyregion(checkthreadviolationrepaintmanager.java:66) @ javax.swing.jcomponent.repaint(jcomponent.java:4793) @ java.awt.component.repaint(component.java:3297) @ javax.swing.jlayeredpane.addimpl(jlayeredpane.java:232) @ java.awt.container.add(container.java:966) @ javax.swing.jrootpane.setcontentpane(jrootpane.java:625) @ javax.swing.jrootpane.<init>(jrootpane.java:367) @ javax.swing.jframe.createrootpane(jframe.java:277) @ javax.swing.jframe.frameinit(jframe.java:258) @ javax.swing.jframe.<init>(jframe.java:181) @ cc.nisc.mapping.controls.tools.fxbrowser.<init>(fxbrowser.java:36) @ cc.nisc.mapping.controls.tools.fxbrowser.showbrowser(fxbrowser.java:22) @ cc.nisc.mapping.controls.tools.streetviewtool.onmousedown(streetviewtool.java:99) @ cc.nisc.mapping.esri.controls.core.nisctool.onmousedown(nisctool.java:135) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ com.esri.arcgis.interop.objectproxy.a(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.invoke(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.handlevtblinvokecallbacknative(native method) @ com.esri.arcgis.interop.nativeobjectproxy$0.run(unknown source) @ com.esri.arcgis.interop.stathread.b(unknown source) @ com.esri.arcgis.interop.stathread.a(unknown source) @ com.esri.arcgis.interop.stathread.post(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.a(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.executevtblcallback(unknown source) @ com.esri.arcgis.interop.nativeobjref.runmessagepump(native method) @ com.esri.arcgis.interop.stathread.run(unknown source) @ java.lang.thread.run(thread.java:745) edt violation detected javax.swing.jrootpane[,0,0,0x0,invalid,layout=javax.swing.jrootpane$rootlayout,alignmentx=0.0,alignmenty=0.0,border=javax.swing.plaf.synth.synthborder@4709b1,flags=1,maximumsize=,minimumsize=,preferredsize=] @ java.lang.thread.getstacktrace(thread.java:1589) @ cc.nisc.gui.checkthreadviolationrepaintmanager.checkthreadviolations(checkthreadviolationrepaintmanager.java:75) @ cc.nisc.gui.checkthreadviolationrepaintmanager.adddirtyregion(checkthreadviolationrepaintmanager.java:66) @ javax.swing.jcomponent.repaint(jcomponent.java:4793) @ java.awt.component.repaint(component.java:3297) @ javax.swing.jcomponent.setborder(jcomponent.java:1800) @ javax.swing.plaf.synth.synthstyle.installdefaults(synthstyle.java:913) @ javax.swing.plaf.synth.synthlookandfeel.updatestyle(synthlookandfeel.java:265) @ javax.swing.plaf.synth.synthrootpaneui.updatestyle(synthrootpaneui.java:94) @ javax.swing.plaf.synth.synthrootpaneui.installdefaults(synthrootpaneui.java:59) @ javax.swing.plaf.basic.basicrootpaneui.installui(basicrootpaneui.java:56) @ javax.swing.jcomponent.setui(jcomponent.java:664) @ javax.swing.jrootpane.setui(jrootpane.java:473) @ javax.swing.jrootpane.updateui(jrootpane.java:483) @ javax.swing.jrootpane.<init>(jrootpane.java:370) @ javax.swing.jframe.createrootpane(jframe.java:277) @ javax.swing.jframe.frameinit(jframe.java:258) @ javax.swing.jframe.<init>(jframe.java:181) @ cc.nisc.mapping.controls.tools.fxbrowser.<init>(fxbrowser.java:36) @ cc.nisc.mapping.controls.tools.fxbrowser.showbrowser(fxbrowser.java:22) @ cc.nisc.mapping.controls.tools.streetviewtool.onmousedown(streetviewtool.java:99) @ cc.nisc.mapping.esri.controls.core.nisctool.onmousedown(nisctool.java:135) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ com.esri.arcgis.interop.objectproxy.a(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.invoke(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.handlevtblinvokecallbacknative(native method) @ com.esri.arcgis.interop.nativeobjectproxy$0.run(unknown source) @ com.esri.arcgis.interop.stathread.b(unknown source) @ com.esri.arcgis.interop.stathread.a(unknown source) @ com.esri.arcgis.interop.stathread.post(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.a(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.executevtblcallback(unknown source) @ com.esri.arcgis.interop.nativeobjref.runmessagepump(native method) @ com.esri.arcgis.interop.stathread.run(unknown source) @ java.lang.thread.run(thread.java:745) edt violation detected javax.swing.jpanel[,0,0,0x0,invalid,layout=java.awt.flowlayout,alignmentx=0.0,alignmenty=0.0,border=javax.swing.plaf.synth.synthborder@1cd75df,flags=9,maximumsize=,minimumsize=,preferredsize=] @ java.lang.thread.getstacktrace(thread.java:1589) @ cc.nisc.gui.checkthreadviolationrepaintmanager.checkthreadviolations(checkthreadviolationrepaintmanager.java:75) @ cc.nisc.gui.checkthreadviolationrepaintmanager.adddirtyregion(checkthreadviolationrepaintmanager.java:66) @ javax.swing.jcomponent.repaint(jcomponent.java:4793) @ java.awt.component.repaint(component.java:3297) @ javax.swing.jcomponent.setborder(jcomponent.java:1800) @ javax.swing.plaf.synth.synthstyle.installdefaults(synthstyle.java:913) @ javax.swing.plaf.synth.synthlookandfeel.updatestyle(synthlookandfeel.java:265) @ javax.swing.plaf.synth.synthpanelui.updatestyle(synthpanelui.java:117) @ javax.swing.plaf.synth.synthpanelui.installdefaults(synthpanelui.java:100) @ javax.swing.plaf.basic.basicpanelui.installui(basicpanelui.java:56) @ javax.swing.plaf.synth.synthpanelui.installui(synthpanelui.java:62) @ javax.swing.jcomponent.setui(jcomponent.java:664) @ javax.swing.jpanel.setui(jpanel.java:153) @ javax.swing.jpanel.updateui(jpanel.java:126) @ javax.swing.jpanel.<init>(jpanel.java:86) @ javax.swing.jpanel.<init>(jpanel.java:109) @ javax.swing.jpanel.<init>(jpanel.java:117) @ cc.nisc.mapping.controls.tools.fxbrowser.initcomponents(fxbrowser.java:52) @ cc.nisc.mapping.controls.tools.fxbrowser.<init>(fxbrowser.java:37) @ cc.nisc.mapping.controls.tools.fxbrowser.showbrowser(fxbrowser.java:22) @ cc.nisc.mapping.controls.tools.streetviewtool.onmousedown(streetviewtool.java:99) @ cc.nisc.mapping.esri.controls.core.nisctool.onmousedown(nisctool.java:135) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ com.esri.arcgis.interop.objectproxy.a(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.invoke(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.handlevtblinvokecallbacknative(native method) @ com.esri.arcgis.interop.nativeobjectproxy$0.run(unknown source) @ com.esri.arcgis.interop.stathread.b(unknown source) @ com.esri.arcgis.interop.stathread.a(unknown source) @ com.esri.arcgis.interop.stathread.post(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.a(unknown source) @ com.esri.arcgis.interop.nativeobjectproxy.executevtblcallback(unknown source) @ com.esri.arcgis.interop.nativeobjref.runmessagepump(native method) @ com.esri.arcgis.interop.stathread.run(unknown source) @ java.lang.thread.run(thread.java:745)
you can use fxbrowser
class show webpage in javafx webview
.coz i'm using in 1 of project
you can use calling
fxbrowser.showbrowser("url want show");
the fxbrowser class
import java.awt.borderlayout; import java.awt.component; import javafx.application.platform; import javafx.embed.swing.jfxpanel; import javafx.scene.scene; import javafx.scene.web.webengine; import javafx.scene.web.webview; import javax.swing.jframe; import javax.swing.jpanel; public class fxbrowser extends jframe { private jpanel webviewpanel; private final javafxbrowser browser; private string url; private static fxbrowser fxbrowser; public static void showbrowser(string url) { if (fxbrowser == null) { fxbrowser = new fxbrowser(); } if (fxbrowser.isvisible()) { return; } fxbrowser.url = url; fxbrowser.setvisible(true); fxbrowser.loadpanel(); } public static void showbrowser() { showbrowser("http://www.bing.com"); } private fxbrowser() { initcomponents(); setsize(1024, 600); setlocationrelativeto(null); setdefaultcloseoperation(jframe.hide_on_close); settitle("browser"); browser = new javafxbrowser(); webviewpanel.add(browser.getcomponent(), borderlayout.center); browser.load(); } public void loadpanel() { browser.seturl(url); } private void initcomponents() { webviewpanel = new javax.swing.jpanel(); webviewpanel.setlayout(new java.awt.borderlayout()); getcontentpane().add(webviewpanel, java.awt.borderlayout.center); pack(); } } class javafxbrowser { jfxpanel fxpanel = new jfxpanel(); webengine webengine; webview webview; public void load() { platform.runlater(new runnable() { // run initfx javafx-thread @override public void run() { webview = new webview(); fxpanel.setscene(new scene(webview)); webengine = webview.getengine(); } }); } public component getcomponent() { return fxpanel; } public void seturl(final string url) { platform.runlater(new runnable() { // run initfx javafx-thread @override public void run() { webengine.load(url); } }); } }
sample usage
import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.swingutilities; public class main extends jframe { public main() { jbutton button = new jbutton("oops"); button.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent e) { fxbrowser.showbrowser("http://demo.borland.com/gmopost/"); } }); add(button); pack(); setlocationrelativeto(null); setdefaultcloseoperation(jframe.exit_on_close); } public static void main(string[] args) { swingutilities.invokelater(new runnable() { public void run() { new main().setvisible(true); } }); } }
Comments
Post a Comment