问题
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