JavaFx 中的 jxBrowser - 线程异常 "JavaFX Application Thread" java.lang.IllegalStateException:无法获取本机 window 句柄
jxBrowser in JavaFx - Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: Failed to get native window handle
我刚刚尝试将 jxBrowser 添加到我的 jfx 应用程序,
这是我的对象:
class fxBrowserPane extends MyPane{
private Button _go;
private TextField _addr;
private HBox _bar;
private BorderPane _bp;
private BrowserView _nodevW;
private Browser _browser;
private String url;
public fxBrowserPane(JSONObject json){
super(json);
url = jsonobj.getString("url"); //url is https://www.google.com
node = new AnchorPane();
_bp = new BorderPane();
_bar = new HBox(); //pannello con la barra degli indirizzi
_go = new Button();
_go.setText("GO");
_addr = new TextField();
_bar.setMaxWidth(Double.MAX_VALUE);
_addr.setMaxWidth(Double.MAX_VALUE);
_bar.getChildren().addAll(_addr,_go);
HBox.setHgrow(_addr, Priority.ALWAYS);
_bar.setPadding(new Insets(1));
_bar.setAlignment(Pos.BASELINE_CENTER);
_bp.setTop(_bar);
}
//this is my start method:
public int start(){
Engine engine = Engine.newInstance(
EngineOptions.newBuilder(HARDWARE_ACCELERATED).enableIncognito().build());
_browser = engine.newBrowser();
_browser.navigation().loadUrl(url);
_nodevW = BrowserView.newInstance(_browser);
if (url != null) {
_addr.setText(url);
(_browser).navigation().loadUrl(url);
System.err.println("load URL:"+url);
}
((AnchorPane)node).getChildren().addAll(_bp);
AnchorPane.setTopAnchor(_bp, 0.0);
AnchorPane.setBottomAnchor(_bp, 0.0);
AnchorPane.setLeftAnchor(_bp, 0.0);
AnchorPane.setRightAnchor(_bp, 0.0);
AnchorPane.setLeftAnchor(_bp, 0.0);
AnchorPane.setRightAnchor(_bp, 0.0);
_bp.setCenter(_nodevW);
return 0;
}
}
这是我得到的奇怪异常:
xception in thread "JavaFX Application Thread" java.lang.IllegalStateException: Failed to get native window handle
at com.teamdev.jxbrowser.view.javafx.internal.Platform.lambda$nativeHandle[=14=](Platform.java:131)
at java.base/java.util.Optional.orElseThrow(Optional.java:408)
at com.teamdev.jxbrowser.view.javafx.internal.Platform.nativeHandle(Platform.java:131)
at com.teamdev.jxbrowser.view.javafx.internal.WindowedWidget.attach(WindowedWidget.java:218)
at com.teamdev.jxbrowser.view.javafx.internal.WindowedWidget.show(WindowedWidget.java:177)
at com.teamdev.jxbrowser.view.javafx.internal.WindowedWidget.setWindow(WindowedWidget.java:319)
at com.teamdev.jxbrowser.view.javafx.internal.WindowedWidget.access00(WindowedWidget.java:46)
at com.teamdev.jxbrowser.view.javafx.internal.WindowedWidget$SceneChangeListener.setScene(WindowedWidget.java:496)
at com.teamdev.jxbrowser.view.javafx.internal.WindowedWidget$SceneChangeListener.lambda$changed[=14=](WindowedWidget.java:478)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
这些是我的 vmargs:
-classpath "D:\ECLIPSE_WORKSPACES\projectBrowser\lib\fxBrowser\lib\jxbrowser-7.13.jar;D:\ECLIPSE_WORKSPACES\projectBrowser\lib\fxBrowser\lib\jxbrowser-win32-7.13.jar;D:\ECLIPSE_WORKSPACES\projectBrowser\lib\fxBrowser\lib\jxbrowser-win64-7.13.jar;D:\ECLIPSE_WORKSPACES\projectBrowser\lib\fxBrowser\lib\jxbrowser-mac-7.13.jar;D:\ECLIPSE_WORKSPACES\projectBrowser\lib\fxBrowser\lib\jxbrowser-linux64-7.13.jar;D:\ECLIPSE_WORKSPACES\projectBrowser\lib\fxBrowser\lib\jxbrowser-linux64-arm-7.13.jar" -Djava.security.auth.login.config=resources/com/sitti/mfz/login/login.config --module-path "D:\Strumenti_di_sviluppo\openjfx-11.0.2_windows-x64_bin-sdk\javafx-sdk-11.0.2\lib" --add-modules=javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.web,javafx.swing --add-opens javafx.graphics/com.sun.glass.ui=ALL-UNNAMED --add-exports javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED --add-opens javafx.graphics/javafx.stage=ALL-UNNAMED --add-opens javafx.graphics/com.sun.javafx.tk.quantum=ALL-UNNAMED
public abstract class MyPane{
protected string type;
protected JSONObject conf;
MyPane(JSONObject jobj){
this.type = jobj.getString("type");
this.conf = jobj;
}
abstract int start();
}
Here 他们建议增加更多 --add.exports
:
In order to run JxBrowser under OpenJFX the following VM parameters must be applied at runtime:
--add-exports javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.stage=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.scene.traversal=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.glass.ui=ALL-UNNAMED
--add-exports java.desktop/sun.awt=ALL-UNNAMED
虽然我必须补充一点,这并没有为我解决问题。
我刚刚尝试将 jxBrowser 添加到我的 jfx 应用程序,
这是我的对象:
class fxBrowserPane extends MyPane{
private Button _go;
private TextField _addr;
private HBox _bar;
private BorderPane _bp;
private BrowserView _nodevW;
private Browser _browser;
private String url;
public fxBrowserPane(JSONObject json){
super(json);
url = jsonobj.getString("url"); //url is https://www.google.com
node = new AnchorPane();
_bp = new BorderPane();
_bar = new HBox(); //pannello con la barra degli indirizzi
_go = new Button();
_go.setText("GO");
_addr = new TextField();
_bar.setMaxWidth(Double.MAX_VALUE);
_addr.setMaxWidth(Double.MAX_VALUE);
_bar.getChildren().addAll(_addr,_go);
HBox.setHgrow(_addr, Priority.ALWAYS);
_bar.setPadding(new Insets(1));
_bar.setAlignment(Pos.BASELINE_CENTER);
_bp.setTop(_bar);
}
//this is my start method:
public int start(){
Engine engine = Engine.newInstance(
EngineOptions.newBuilder(HARDWARE_ACCELERATED).enableIncognito().build());
_browser = engine.newBrowser();
_browser.navigation().loadUrl(url);
_nodevW = BrowserView.newInstance(_browser);
if (url != null) {
_addr.setText(url);
(_browser).navigation().loadUrl(url);
System.err.println("load URL:"+url);
}
((AnchorPane)node).getChildren().addAll(_bp);
AnchorPane.setTopAnchor(_bp, 0.0);
AnchorPane.setBottomAnchor(_bp, 0.0);
AnchorPane.setLeftAnchor(_bp, 0.0);
AnchorPane.setRightAnchor(_bp, 0.0);
AnchorPane.setLeftAnchor(_bp, 0.0);
AnchorPane.setRightAnchor(_bp, 0.0);
_bp.setCenter(_nodevW);
return 0;
}
}
这是我得到的奇怪异常:
xception in thread "JavaFX Application Thread" java.lang.IllegalStateException: Failed to get native window handle
at com.teamdev.jxbrowser.view.javafx.internal.Platform.lambda$nativeHandle[=14=](Platform.java:131)
at java.base/java.util.Optional.orElseThrow(Optional.java:408)
at com.teamdev.jxbrowser.view.javafx.internal.Platform.nativeHandle(Platform.java:131)
at com.teamdev.jxbrowser.view.javafx.internal.WindowedWidget.attach(WindowedWidget.java:218)
at com.teamdev.jxbrowser.view.javafx.internal.WindowedWidget.show(WindowedWidget.java:177)
at com.teamdev.jxbrowser.view.javafx.internal.WindowedWidget.setWindow(WindowedWidget.java:319)
at com.teamdev.jxbrowser.view.javafx.internal.WindowedWidget.access00(WindowedWidget.java:46)
at com.teamdev.jxbrowser.view.javafx.internal.WindowedWidget$SceneChangeListener.setScene(WindowedWidget.java:496)
at com.teamdev.jxbrowser.view.javafx.internal.WindowedWidget$SceneChangeListener.lambda$changed[=14=](WindowedWidget.java:478)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
这些是我的 vmargs:
-classpath "D:\ECLIPSE_WORKSPACES\projectBrowser\lib\fxBrowser\lib\jxbrowser-7.13.jar;D:\ECLIPSE_WORKSPACES\projectBrowser\lib\fxBrowser\lib\jxbrowser-win32-7.13.jar;D:\ECLIPSE_WORKSPACES\projectBrowser\lib\fxBrowser\lib\jxbrowser-win64-7.13.jar;D:\ECLIPSE_WORKSPACES\projectBrowser\lib\fxBrowser\lib\jxbrowser-mac-7.13.jar;D:\ECLIPSE_WORKSPACES\projectBrowser\lib\fxBrowser\lib\jxbrowser-linux64-7.13.jar;D:\ECLIPSE_WORKSPACES\projectBrowser\lib\fxBrowser\lib\jxbrowser-linux64-arm-7.13.jar" -Djava.security.auth.login.config=resources/com/sitti/mfz/login/login.config --module-path "D:\Strumenti_di_sviluppo\openjfx-11.0.2_windows-x64_bin-sdk\javafx-sdk-11.0.2\lib" --add-modules=javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.web,javafx.swing --add-opens javafx.graphics/com.sun.glass.ui=ALL-UNNAMED --add-exports javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED --add-opens javafx.graphics/javafx.stage=ALL-UNNAMED --add-opens javafx.graphics/com.sun.javafx.tk.quantum=ALL-UNNAMED
public abstract class MyPane{
protected string type;
protected JSONObject conf;
MyPane(JSONObject jobj){
this.type = jobj.getString("type");
this.conf = jobj;
}
abstract int start();
}
Here 他们建议增加更多 --add.exports
:
In order to run JxBrowser under OpenJFX the following VM parameters must be applied at runtime:
--add-exports javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.stage=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.scene.traversal=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.glass.ui=ALL-UNNAMED
--add-exports java.desktop/sun.awt=ALL-UNNAMED
虽然我必须补充一点,这并没有为我解决问题。