gpt4 book ai didi

javafx - JxBrowser 无法在 JavaFX 中配置

转载 作者:行者123 更新时间:2023-12-02 01:09:12 27 4
gpt4 key购买 nike

我使用 Tabpane 多个浏览器;当我关闭一个选项卡时,我无法处理主 IPC:

public class JxbrowserDemo extends Application {
@Override
public void start(Stage primaryStage) {
setLevel(Level.ALL);
TabPane tabPane = new TabPane();
tabPane.getTabs().add(createBrowserTab());
tabPane.getTabs().add(createBrowserTab());
StackPane pane = new StackPane();
pane.getChildren().add(tabPane);
Scene scene = new Scene(pane, 500, 400);
primaryStage.setTitle("JxBrowser: JavaFX - Hello World");
primaryStage.setScene(scene);
primaryStage.show();
}

public Tab createBrowserTab() {
Tab tab = new Tab("baidu");
Browser browser = new Browser();
BrowserView browserView = new BrowserView(browser);

tab.setOnClosed(new EventHandler<Event>() {
@Override
public void handle(Event event) {
//last tag close throw exception
//
browser.dispose();
}
});

tab.setContent(browserView);
browser.loadURL("www.google.com");
//tabPane.getTabs().add(tab);
//browserArrayList.add(browser);
return tab;
}

@Override
public void stop() throws Exception {
//dispose here Success
/*browserArrayList.forEach(t->{
t.dispose();
});*/
super.stop();
}

public static void main(String[] args) {
launch(args);
}
}

日志:

02:42:22 信息: Shutting down event queue...
02:42:22 信息: Shutting down event queue... [DONE]
02:42:22 信息: Shutting down event queue...
02:42:22 信息: Shutting down event queue... [DONE]
02:42:22 信息: Channel has been disconnected: SocketChannel{cid=1, bid=1, type=Render}
02:42:22 信息: Channel is disconnected: SocketChannel{cid=1, bid=1, type=Render}
02:42:22 信息: Shutting down event queue...
02:42:22 信息: Shutting down event queue... [DONE]
02:42:22 信息: Shutting down event queue...
02:42:22 信息: Shutting down event queue... [DONE]
02:42:22 信息: IPC connection has been closed. Connection ID: 466160688
02:42:22 信息: Pending IPC connections: 2
02:42:22 信息: Channel has been disconnected: SocketChannel{cid=1, bid=1, type=Browser}
02:42:22 信息: Channel is disconnected: SocketChannel{cid=1, bid=1, type=Browser}
02:42:22 信息: Stopping IPC...
02:42:22 信息: Stopping main channel...
02:42:22 信息: IPC connection has been closed. Connection ID: 466160864
02:42:22 信息: Pending IPC connections: 1
02:42:22 详细: WRITE: ShutdownMessage{type=Shutdown, uid=175, SocketInfo{cid=0, bid=-1, channelType=Main

在这里挂断。

大约五分钟后它抛出异常:

02:42:22 详细: WRITE: ShutdownMessage{type=Shutdown, uid=175, SocketInfo{cid=0, bid=-1, channelType=Main}
Exception in thread "JavaFX Application Thread" com.teamdev.jxbrowser.chromium.internal.ipc.IPCException: Failed to execute shutdown post message.
02:44:22 信息: Shutting down event queue...
02:44:22 信息: Shutting down event queue... [DONE]
02:44:22 信息: Shutting down event queue...
02:44:22 信息: Shutting down event queue... [DONE]
02:44:22 信息: Channel has been disconnected: SocketChannel{cid=0, bid=-1, type=Main}
02:44:22 信息: IPC connection has been closed. Connection ID: 466161040
02:44:22 信息: Pending IPC connections: 0
02:44:22 信息: Chromium process exit code 0

最佳答案

尝试在非 JavaFx 应用程序线程中处理浏览器实例:

        tab.setOnClosed(new EventHandler<Event>() {
@Override
public void handle(Event event) {
//last tag close throw exception
//
new Thread(new Runnable() {
@Override
public void run() {
browser.dispose();
}
}).start();
}
});

关于javafx - JxBrowser 无法在 JavaFX 中配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45913270/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com