目前有一个问题,我无法让我的JFrame和相关的JFXPanel弹出/显示。我已经看过这个网站上的许多其他例子和JFXs使用JFXPanels的其他例子,但都与我的完全不同。我相信我的问题可能在于我使用两个连续的runnables,所以当Swing线程尝试使用它的组件时,JavaFX线程还没有完成?将非常感谢帮助 - 相关代码如下:
注意:我没有收到任何编译或运行时错误。我的问题是,当我希望弹出对话框时,没有任何反应
@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);
}
});
.........
使用以下建议解决方案时收到的错误的堆栈跟踪:
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=]
at java.lang.Thread.getStackTrace(Thread.java:1589)
at cc.nisc.gui.CheckThreadViolationRepaintManager.checkThreadViolations(CheckThreadViolationRepaintManager.java:75)
at cc.nisc.gui.CheckThreadViolationRepaintManager.addDirtyRegion(CheckThreadViolationRepaintManager.java:66)
at javax.swing.JComponent.repaint(JComponent.java:4793)
at java.awt.Component.repaint(Component.java:3297)
at javax.swing.JComponent.setBorder(JComponent.java:1800)
at javax.swing.plaf.synth.SynthStyle.installDefaults(SynthStyle.java:913)
at javax.swing.plaf.synth.SynthLookAndFeel.updateStyle(SynthLookAndFeel.java:265)
at javax.swing.plaf.synth.SynthPanelUI.updateStyle(SynthPanelUI.java:117)
at javax.swing.plaf.synth.SynthPanelUI.installDefaults(SynthPanelUI.java:100)
at javax.swing.plaf.basic.BasicPanelUI.installUI(BasicPanelUI.java:56)
at javax.swing.plaf.synth.SynthPanelUI.installUI(SynthPanelUI.java:62)
at javax.swing.JComponent.setUI(JComponent.java:664)
at javax.swing.JPanel.setUI(JPanel.java:153)
at javax.swing.JPanel.updateUI(JPanel.java:126)
at javax.swing.JPanel.<init>(JPanel.java:86)
at javax.swing.JPanel.<init>(JPanel.java:109)
at javax.swing.JPanel.<init>(JPanel.java:117)
at javax.swing.JRootPane.createGlassPane(JRootPane.java:545)
at javax.swing.JRootPane.<init>(JRootPane.java:365)
at javax.swing.JFrame.createRootPane(JFrame.java:277)
at javax.swing.JFrame.frameInit(JFrame.java:258)
at javax.swing.JFrame.<init>(JFrame.java:181)
at cc.nisc.mapping.controls.tools.FXBrowser.<init>(FXBrowser.java:36)
at cc.nisc.mapping.controls.tools.FXBrowser.showBrowser(FXBrowser.java:22)
at cc.nisc.mapping.controls.tools.StreetViewTool.onMouseDown(StreetViewTool.java:99)
at cc.nisc.mapping.esri.controls.core.NiscTool.onMouseDown(NiscTool.java:135)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.esri.arcgis.interop.ObjectProxy.a(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.invoke(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.handleVtblInvokeCallbackNative(Native Method)
at com.esri.arcgis.interop.NativeObjectProxy$0.run(Unknown Source)
at com.esri.arcgis.interop.STAThread.b(Unknown Source)
at com.esri.arcgis.interop.STAThread.a(Unknown Source)
at com.esri.arcgis.interop.STAThread.post(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.a(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.executeVtblCallback(Unknown Source)
at com.esri.arcgis.interop.NativeObjRef.runMessagePump(Native Method)
at com.esri.arcgis.interop.STAThread.run(Unknown Source)
at 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=]
at java.lang.Thread.getStackTrace(Thread.java:1589)
at cc.nisc.gui.CheckThreadViolationRepaintManager.checkThreadViolations(CheckThreadViolationRepaintManager.java:75)
at cc.nisc.gui.CheckThreadViolationRepaintManager.addDirtyRegion(CheckThreadViolationRepaintManager.java:66)
at javax.swing.JComponent.repaint(JComponent.java:4793)
at java.awt.Component.repaint(Component.java:3297)
at javax.swing.JComponent.setBorder(JComponent.java:1800)
at javax.swing.plaf.synth.SynthStyle.installDefaults(SynthStyle.java:913)
at javax.swing.plaf.synth.SynthLookAndFeel.updateStyle(SynthLookAndFeel.java:265)
at javax.swing.plaf.synth.SynthPanelUI.updateStyle(SynthPanelUI.java:117)
at javax.swing.plaf.synth.SynthPanelUI.installDefaults(SynthPanelUI.java:100)
at javax.swing.plaf.basic.BasicPanelUI.installUI(BasicPanelUI.java:56)
at javax.swing.plaf.synth.SynthPanelUI.installUI(SynthPanelUI.java:62)
at javax.swing.JComponent.setUI(JComponent.java:664)
at javax.swing.JPanel.setUI(JPanel.java:153)
at javax.swing.JPanel.updateUI(JPanel.java:126)
at javax.swing.JPanel.<init>(JPanel.java:86)
at javax.swing.JPanel.<init>(JPanel.java:109)
at javax.swing.JPanel.<init>(JPanel.java:117)
at javax.swing.JRootPane.createContentPane(JRootPane.java:520)
at javax.swing.JRootPane.<init>(JRootPane.java:367)
at javax.swing.JFrame.createRootPane(JFrame.java:277)
at javax.swing.JFrame.frameInit(JFrame.java:258)
at javax.swing.JFrame.<init>(JFrame.java:181)
at cc.nisc.mapping.controls.tools.FXBrowser.<init>(FXBrowser.java:36)
at cc.nisc.mapping.controls.tools.FXBrowser.showBrowser(FXBrowser.java:22)
at cc.nisc.mapping.controls.tools.StreetViewTool.onMouseDown(StreetViewTool.java:99)
at cc.nisc.mapping.esri.controls.core.NiscTool.onMouseDown(NiscTool.java:135)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.esri.arcgis.interop.ObjectProxy.a(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.invoke(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.handleVtblInvokeCallbackNative(Native Method)
at com.esri.arcgis.interop.NativeObjectProxy$0.run(Unknown Source)
at com.esri.arcgis.interop.STAThread.b(Unknown Source)
at com.esri.arcgis.interop.STAThread.a(Unknown Source)
at com.esri.arcgis.interop.STAThread.post(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.a(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.executeVtblCallback(Unknown Source)
at com.esri.arcgis.interop.NativeObjRef.runMessagePump(Native Method)
at com.esri.arcgis.interop.STAThread.run(Unknown Source)
at 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]
at java.lang.Thread.getStackTrace(Thread.java:1589)
at cc.nisc.gui.CheckThreadViolationRepaintManager.checkThreadViolations(CheckThreadViolationRepaintManager.java:75)
at cc.nisc.gui.CheckThreadViolationRepaintManager.addDirtyRegion(CheckThreadViolationRepaintManager.java:66)
at javax.swing.JComponent.repaint(JComponent.java:4793)
at javax.swing.JComponent.repaint(JComponent.java:4808)
at javax.swing.JLayeredPane.setLayer(JLayeredPane.java:374)
at javax.swing.JLayeredPane.setLayer(JLayeredPane.java:345)
at javax.swing.JLayeredPane.addImpl(JLayeredPane.java:225)
at java.awt.Container.add(Container.java:966)
at javax.swing.JRootPane.setContentPane(JRootPane.java:625)
at javax.swing.JRootPane.<init>(JRootPane.java:367)
at javax.swing.JFrame.createRootPane(JFrame.java:277)
at javax.swing.JFrame.frameInit(JFrame.java:258)
at javax.swing.JFrame.<init>(JFrame.java:181)
at cc.nisc.mapping.controls.tools.FXBrowser.<init>(FXBrowser.java:36)
at cc.nisc.mapping.controls.tools.FXBrowser.showBrowser(FXBrowser.java:22)
at cc.nisc.mapping.controls.tools.StreetViewTool.onMouseDown(StreetViewTool.java:99)
at cc.nisc.mapping.esri.controls.core.NiscTool.onMouseDown(NiscTool.java:135)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.esri.arcgis.interop.ObjectProxy.a(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.invoke(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.handleVtblInvokeCallbackNative(Native Method)
at com.esri.arcgis.interop.NativeObjectProxy$0.run(Unknown Source)
at com.esri.arcgis.interop.STAThread.b(Unknown Source)
at com.esri.arcgis.interop.STAThread.a(Unknown Source)
at com.esri.arcgis.interop.STAThread.post(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.a(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.executeVtblCallback(Unknown Source)
at com.esri.arcgis.interop.NativeObjRef.runMessagePump(Native Method)
at com.esri.arcgis.interop.STAThread.run(Unknown Source)
at 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=]
at java.lang.Thread.getStackTrace(Thread.java:1589)
at cc.nisc.gui.CheckThreadViolationRepaintManager.checkThreadViolations(CheckThreadViolationRepaintManager.java:75)
at cc.nisc.gui.CheckThreadViolationRepaintManager.addDirtyRegion(CheckThreadViolationRepaintManager.java:66)
at javax.swing.JComponent.repaint(JComponent.java:4793)
at java.awt.Component.repaint(Component.java:3297)
at javax.swing.JLayeredPane.addImpl(JLayeredPane.java:232)
at java.awt.Container.add(Container.java:966)
at javax.swing.JRootPane.setContentPane(JRootPane.java:625)
at javax.swing.JRootPane.<init>(JRootPane.java:367)
at javax.swing.JFrame.createRootPane(JFrame.java:277)
at javax.swing.JFrame.frameInit(JFrame.java:258)
at javax.swing.JFrame.<init>(JFrame.java:181)
at cc.nisc.mapping.controls.tools.FXBrowser.<init>(FXBrowser.java:36)
at cc.nisc.mapping.controls.tools.FXBrowser.showBrowser(FXBrowser.java:22)
at cc.nisc.mapping.controls.tools.StreetViewTool.onMouseDown(StreetViewTool.java:99)
at cc.nisc.mapping.esri.controls.core.NiscTool.onMouseDown(NiscTool.java:135)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.esri.arcgis.interop.ObjectProxy.a(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.invoke(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.handleVtblInvokeCallbackNative(Native Method)
at com.esri.arcgis.interop.NativeObjectProxy$0.run(Unknown Source)
at com.esri.arcgis.interop.STAThread.b(Unknown Source)
at com.esri.arcgis.interop.STAThread.a(Unknown Source)
at com.esri.arcgis.interop.STAThread.post(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.a(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.executeVtblCallback(Unknown Source)
at com.esri.arcgis.interop.NativeObjRef.runMessagePump(Native Method)
at com.esri.arcgis.interop.STAThread.run(Unknown Source)
at 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=]
at java.lang.Thread.getStackTrace(Thread.java:1589)
at cc.nisc.gui.CheckThreadViolationRepaintManager.checkThreadViolations(CheckThreadViolationRepaintManager.java:75)
at cc.nisc.gui.CheckThreadViolationRepaintManager.addDirtyRegion(CheckThreadViolationRepaintManager.java:66)
at javax.swing.JComponent.repaint(JComponent.java:4793)
at java.awt.Component.repaint(Component.java:3297)
at javax.swing.JComponent.setBorder(JComponent.java:1800)
at javax.swing.plaf.synth.SynthStyle.installDefaults(SynthStyle.java:913)
at javax.swing.plaf.synth.SynthLookAndFeel.updateStyle(SynthLookAndFeel.java:265)
at javax.swing.plaf.synth.SynthRootPaneUI.updateStyle(SynthRootPaneUI.java:94)
at javax.swing.plaf.synth.SynthRootPaneUI.installDefaults(SynthRootPaneUI.java:59)
at javax.swing.plaf.basic.BasicRootPaneUI.installUI(BasicRootPaneUI.java:56)
at javax.swing.JComponent.setUI(JComponent.java:664)
at javax.swing.JRootPane.setUI(JRootPane.java:473)
at javax.swing.JRootPane.updateUI(JRootPane.java:483)
at javax.swing.JRootPane.<init>(JRootPane.java:370)
at javax.swing.JFrame.createRootPane(JFrame.java:277)
at javax.swing.JFrame.frameInit(JFrame.java:258)
at javax.swing.JFrame.<init>(JFrame.java:181)
at cc.nisc.mapping.controls.tools.FXBrowser.<init>(FXBrowser.java:36)
at cc.nisc.mapping.controls.tools.FXBrowser.showBrowser(FXBrowser.java:22)
at cc.nisc.mapping.controls.tools.StreetViewTool.onMouseDown(StreetViewTool.java:99)
at cc.nisc.mapping.esri.controls.core.NiscTool.onMouseDown(NiscTool.java:135)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.esri.arcgis.interop.ObjectProxy.a(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.invoke(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.handleVtblInvokeCallbackNative(Native Method)
at com.esri.arcgis.interop.NativeObjectProxy$0.run(Unknown Source)
at com.esri.arcgis.interop.STAThread.b(Unknown Source)
at com.esri.arcgis.interop.STAThread.a(Unknown Source)
at com.esri.arcgis.interop.STAThread.post(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.a(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.executeVtblCallback(Unknown Source)
at com.esri.arcgis.interop.NativeObjRef.runMessagePump(Native Method)
at com.esri.arcgis.interop.STAThread.run(Unknown Source)
at 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=]
at java.lang.Thread.getStackTrace(Thread.java:1589)
at cc.nisc.gui.CheckThreadViolationRepaintManager.checkThreadViolations(CheckThreadViolationRepaintManager.java:75)
at cc.nisc.gui.CheckThreadViolationRepaintManager.addDirtyRegion(CheckThreadViolationRepaintManager.java:66)
at javax.swing.JComponent.repaint(JComponent.java:4793)
at java.awt.Component.repaint(Component.java:3297)
at javax.swing.JComponent.setBorder(JComponent.java:1800)
at javax.swing.plaf.synth.SynthStyle.installDefaults(SynthStyle.java:913)
at javax.swing.plaf.synth.SynthLookAndFeel.updateStyle(SynthLookAndFeel.java:265)
at javax.swing.plaf.synth.SynthPanelUI.updateStyle(SynthPanelUI.java:117)
at javax.swing.plaf.synth.SynthPanelUI.installDefaults(SynthPanelUI.java:100)
at javax.swing.plaf.basic.BasicPanelUI.installUI(BasicPanelUI.java:56)
at javax.swing.plaf.synth.SynthPanelUI.installUI(SynthPanelUI.java:62)
at javax.swing.JComponent.setUI(JComponent.java:664)
at javax.swing.JPanel.setUI(JPanel.java:153)
at javax.swing.JPanel.updateUI(JPanel.java:126)
at javax.swing.JPanel.<init>(JPanel.java:86)
at javax.swing.JPanel.<init>(JPanel.java:109)
at javax.swing.JPanel.<init>(JPanel.java:117)
at cc.nisc.mapping.controls.tools.FXBrowser.initComponents(FXBrowser.java:52)
at cc.nisc.mapping.controls.tools.FXBrowser.<init>(FXBrowser.java:37)
at cc.nisc.mapping.controls.tools.FXBrowser.showBrowser(FXBrowser.java:22)
at cc.nisc.mapping.controls.tools.StreetViewTool.onMouseDown(StreetViewTool.java:99)
at cc.nisc.mapping.esri.controls.core.NiscTool.onMouseDown(NiscTool.java:135)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.esri.arcgis.interop.ObjectProxy.a(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.invoke(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.handleVtblInvokeCallbackNative(Native Method)
at com.esri.arcgis.interop.NativeObjectProxy$0.run(Unknown Source)
at com.esri.arcgis.interop.STAThread.b(Unknown Source)
at com.esri.arcgis.interop.STAThread.a(Unknown Source)
at com.esri.arcgis.interop.STAThread.post(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.a(Unknown Source)
at com.esri.arcgis.interop.NativeObjectProxy.executeVtblCallback(Unknown Source)
at com.esri.arcgis.interop.NativeObjRef.runMessagePump(Native Method)
at com.esri.arcgis.interop.STAThread.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
答案 0 :(得分:1)
您可以使用此FXBrowser
课程在JavaFX WebView
中显示网页。因为我在我的某个项目中使用此功能
您可以通过致电
来使用此功能FXBrowser.showBrowser("url you want to show");
FXBrowser 类
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() { // this will run initFX as 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() { // this will run initFX as JavaFX-Thread
@Override
public void run() {
webEngine.load(url);
}
});
}
}
样本使用
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);
}
});
}
}