How can I open a new Stage on the external monitor?

只愿长相守 提交于 2019-12-05 05:10:23

问题


I have an external monitor plugged into my laptop. I want to display a new Stage on this external screen in fullscreen, undecorated and modal mode. I know how to achieve all of this in pure Java/Swing combination, but I'm stucked with JavaFX implementation of such functionality.

I know, there is a Screen API, which I can use e.g to get screen list, say:

List<Screen> allScreens = Screen.getScreens();

...but I don't know where I could go from here.

UPDATE : 2014/08/03, 22:21

I've found the way to solve my problem, so I've decided to share my approach to it. So far I haven't found a better solution.

Button.setOnAction(new EventHandler<ActionEvent>() {
    @Override
    public void handle(ActionEvent ae) {
        List<Screen> allScreens = Screen.getScreens();
        if (allScreens.size() > 1) {
            Screen secondaryScreen = allScreens.get(1);
            Rectangle2D bounds = secondaryScreen.getVisualBounds();

            Stage stage = new Stage();
            stage.setX(bounds.getMinX());
            stage.setY(bounds.getMinY());
            stage.setWidth(bounds.getWidth());
            stage.setHeight(bounds.getHeight());

            stage.initStyle(StageStyle.UNDECORATED);
            stage.initModality(Modality.APPLICATION_MODAL);
            stage.show();

        } else {
            Stage stage = new Stage();
            stage.setFullScreen(true);

            stage.initStyle(StageStyle.UNDECORATED);
            stage.initModality(Modality.APPLICATION_MODAL);
            stage.show();
        }
    }
});

来源:https://stackoverflow.com/questions/25108189/how-can-i-open-a-new-stage-on-the-external-monitor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!