如何解决JavaFx 中的 jxBrowser - 线程“JavaFX 应用程序线程”中的异常 java.lang.IllegalStateException:无法获取本机窗口句柄
我只是尝试将 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);
_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$0(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.access$1500(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$0(WindowedWidget.java:478)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(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$3(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
:
为了在 OpenJFX 下运行 JxBrowser,必须在运行时应用以下 VM 参数:
--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
尽管我必须补充一点,这并没有为我解决问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。