我正在处理具有通常登录窗口的应用程序(JavaFX' 8对话框),然后在接受它时打开新窗口(JFrame)。如果它在多监视器环境中运行,它应该工作,JFrame将在JavaFX'的同一监视器上打开。 8对话框已关闭。
现在我可以在显示器上打开JFrame,我可以手动选择
GraphicsEnvironment
,但此时我无法弄清楚JavaFX' 8对话框已关闭。有任何想法吗?谢谢。
答案 0 :(得分:0)
当您关闭JavaFX对话框时,也许可以保存您的位置:
private void saveWindowPosition() {
Preferences userPrefs = Preferences.userNodeForPackage(getClass());
userPrefs.putDouble("stage.x", primaryStage.getX());
userPrefs.putDouble("stage.y", primaryStage.getY());
}
并按如下方式阅读:
private void restoreWindowPosition() {
Preferences userPrefs = Preferences.userNodeForPackage(getClass());
// get window location from user preferences: use x=100, y=100 as
// default
double x = userPrefs.getDouble("stage.x", 100);
double y = userPrefs.getDouble("stage.y", 100);
primaryStage.setX(x);
primaryStage.setY(y);
}
答案 1 :(得分:0)
嗯,这对我有用:
/**
* As an argument you pass a Scene(of Java FX 8 Dialog in my example),
* by closing it you want JFrame to open on same monitor.
**/
public static int getActiveStageLocation(Scene scene){
List interScreens = Screen.getScreensForRectangle(scene.getWindow().getX(),
scene.getWindow().getY(),
scene.getWindow().getWidth(),
scene.getWindow().getHeight());
Screen activeScreen = (Screen) interScreens.get(0);
Rectangle2D r = activeScreen.getBounds();
double position = r.getMinX();
return (int) position;
}
然后您可以简单地设置JFrame的位置:
/**
* Some code for instantiating frame and so on....
* Parameter scene you could get for example from your FXML
**/
myFrame.setLocation(getActiveStageLocation(scene), myFrame.getY());
myFrame.setVisible(true);