gpt4 book ai didi

java - 隐藏阶段时 JxBrowser View 消失

转载 作者:行者123 更新时间:2023-11-30 10:50:34 25 4
gpt4 key购买 nike

我在我的 javafx 应用程序中使用 jxbrowser 是这样的:

public class Main extends Application {

private Stage primaryStage;

private Browser browser;

private boolean firstMinimize;

private TrayIcon trayIcon;

public static void main(String[] args) {

launch(args);

}

@Override
public void start(Stage primaryStage) {

this.primaryStage = primaryStage;

firstMinimize = true;

Platform.setImplicitExit(false);

createTrayIcon();

browser = new Browser();

BrowserView browserView = new BrowserView(browser);

StackPane pane = new StackPane();

pane.getChildren().add(browserView);

Scene scene = new Scene(pane, 380, 500);

primaryStage.initStyle(StageStyle.UNDECORATED);

primaryStage.setScene(scene);

primaryStage.show();

browser.addRenderListener(new RenderAdapter() {
@Override
public void onRenderGone(RenderEvent event) {

System.out.println("here called...");

Browser browser = event.getBrowser();
// Restore Browser instance by loading the same URL
browser.loadURL(browser.getURL());
}
});

initialize();

// if not logged in

showLogin();

}

public void initialize() {

initCloseButton(primaryStage);

initMinimizeButton(primaryStage);

}

public void initCloseButton(Stage primaryStage) {

browser.registerFunction("Close", new BrowserFunction() {

@Override
public JSValue invoke(JSValue... args) {

Platform.runLater(new Runnable() {

@Override
public void run() {

closeToTray(primaryStage);

}
});

return null;

}

});

}

public void initMinimizeButton(Stage primaryStage) {

browser.registerFunction("Minimize", new BrowserFunction() {

@Override
public JSValue invoke(JSValue... args) {

Platform.runLater(new Runnable() {

@Override
public void run() {

primaryStage.setIconified(true);

}
});

return null;

}

});

}


public void createTrayIcon() {

if (SystemTray.isSupported()) {

SystemTray tray = SystemTray.getSystemTray();

java.awt.Image image = null;

try {

URL url = new URL("http://www.digitalphotoartistry.com/rose1.jpg");

image = ImageIO.read(url);

} catch (IOException ex) {

System.out.println(ex);

}


final ActionListener closeListener = new ActionListener() {

@Override
public void actionPerformed(java.awt.event.ActionEvent e) {

System.exit(0);

}

};

final ActionListener showListener = new ActionListener() {

@Override
public void actionPerformed(java.awt.event.ActionEvent e) {

Platform.runLater(new Runnable() {

@Override
public void run() {

// primaryStage.setOpacity(0);

primaryStage.show();

}

});

}

};

PopupMenu popup = new PopupMenu();

MenuItem showItem = new MenuItem("Show");
showItem.addActionListener(showListener);
popup.add(showItem);

MenuItem closeItem = new MenuItem("Close");
closeItem.addActionListener(closeListener);
popup.add(closeItem);

trayIcon = new TrayIcon(image, "RezRem", popup);

trayIcon.addActionListener(showListener);

try {

tray.add(trayIcon);

} catch (AWTException e) {

System.err.println(e);

}

}

}

public void showMinimizeMessage() {

if (firstMinimize) {

trayIcon.displayMessage("some message",
"Some other message.",
TrayIcon.MessageType.INFO);

firstMinimize = false;

}

}

private void closeToTray(Stage primaryStage) {

Platform.runLater(new Runnable() {

@Override

public void run() {

if (SystemTray.isSupported()) {

// primaryStage.setOpacity(0);

primaryStage.hide();

showMinimizeMessage();

}
else {

System.exit(0);

}

}
});
}

public void showLogin() {

browser.loadURL(Main.class.getResource("templates/login.html").toExternalForm());

browser.registerFunction("Login", new BrowserFunction() {

@Override
public JSValue invoke(JSValue... args) {

for (JSValue arg : args) {

System.out.println("arg = " + arg.getString());

}

return JSValue.create("Hello!");

}

});

}

}

我已将关闭按钮设置为在单击函数“closeToTray”时隐藏舞台。(为了将其最小化到系统托盘)但是随后调用 stage.show() 会打开浏览器,但浏览器 View 只是整体白色,换句话说,呈现的页面就这样消失了。这是最小化到系统托盘之前和之后的屏幕截图: Before clicking close btn , after clicking show from system tray

有什么想法吗?

提前致谢

最佳答案

这是 JxBrowser 中的一个已知问题6.0.2。该修复程序将在一周后发布的下一个更新中提供。

关于java - 隐藏阶段时 JxBrowser View 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35030907/

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