Screen screen = Screen.getPrimary(); Rectangle2D bounds = screen.getVisualBounds(); primaryStage.setX(bounds.getMinX()); primaryStage.setY(bounds.getMinY()); primaryStage.setWidth(bounds.getWidth()); primaryStage.setHeight(bounds.getHeight());
primaryStage.getWidth(), primaryStage.getHeight()).get(0); Rectangle2D bounds = screen.getVisualBounds(); maximizedBox = new BoundingBox(bounds.getMinX(), bounds.getMinY(),
private void defaultStageStatus() { Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds(); stage.setX((primScreenBounds.getWidth() - stage.getWidth()) / 2); stage.setY((primScreenBounds.getHeight() - stage.getHeight()) / 4); stage.setMaximized(true); }
public HelpPopup(Region content) { getStyleClass().setAll("pdfsam-help-popup"); setAutoHide(true); setHideOnEscape(true); setAutoFix(true); this.content = content; this.content.setMaxWidth(Screen.getPrimary().getVisualBounds().getWidth() / 3); }
Label label = new Label("monitor " + i); stage.setScene(new Scene(label)); System.out.println(Screen.getScreens().size()); Screen screen = Screen.getScreens().get(i); //i is the monitor id //set the position to one of the "slave"-monitors: stage.setX(screen.getVisualBounds().getMinX()); stage.setY(screen.getVisualBounds().getMinY()); //set the dimesions to the screen size: stage.setWidth(screen.getVisualBounds().getWidth()); stage.setHeight(screen.getVisualBounds().getHeight()); //show the stage without decorations (titlebar and window borders): stage.initStyle(StageStyle.UNDECORATED); stage.show();
//stage.setResizable(true); Screen screen = Screen.getPrimary(); Rectangle2D bounds = screen.getVisualBounds(); stage.setX(bounds.getMinX()); stage.setY(bounds.getMinY()); stage.setWidth(bounds.getWidth()); stage.setHeight(bounds.getHeight());
Scene scene = stage.getScene(); Screen primaryScreen = Screen.getPrimary(); Rectangle2D visualBounds = primaryScreen.getVisualBounds(); double width = visualBounds.getWidth(); double height = visualBounds.getHeight(); scene = new Scene(root, width, height);
Screen screen = Screen.getPrimary(); Rectangle2D bounds = screen.getVisualBounds(); primaryStage.setX(bounds.getMinX()); primaryStage.setY(bounds.getMinY()); primaryStage.setWidth(bounds.getWidth()); primaryStage.setHeight(bounds.getHeight());
for (Screen screen : Screen.getScreens()) { Rectangle2D bounds = screen.getVisualBounds(); Button btn = new Button("Move me to Screen " + index++); btn.setOnAction((e) -> { stage.setX(bounds.getMinX() + 100); stage.setY(bounds.getMinY() + 100); }); root.getChildren().add(btn); }
public class ScreenBounds extends Application { @Override public void start(Stage primaryStage) { Screen screen = Screen.getPrimary(); System.out.println("ScreenBounds : " + screen.getBounds() + "\nVisualBounds : " + screen.getVisualBounds()); Platform.exit(); } /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } }
public static double getScreenHeight() { return Screen.getPrimary().getVisualBounds().getHeight(); }
Screen screen2 = Screen.getScreens().get(primaryMon); Stage stage2 = new Stage(); stage2.setScene(new Scene(new Label("primary"))); //we need to set the window position to the primary monitor: stage2.setX(screen2.getVisualBounds().getMinX()); stage2.setY(screen2.getVisualBounds().getMinY()); stage2.setFullScreen(true); stage2.show();
public static double getScreenWidth() { return Screen.getPrimary().getVisualBounds().getWidth(); }
Screen screen = Screen.getPrimary(); Rectangle2D bounds = screen.getVisualBounds(); //let the window use the left half screen: stage.setX(bounds.getMinX()); stage.setY(bounds.getMinY()); stage.setWidth(bounds.getWidth() / 2); stage.setHeight(bounds.getHeight()); VBox vBox = new VBox(); vBox.setStyle("-fx-background-color: blue;"); Rectangle rect = new Rectangle(); rect.setStyle("-fx-fill: red;"); vBox.getChildren().add(rect); //not necessary, because always max size (root element of the scene): //vBox.minWidthProperty().bind(stage.widthProperty()); //vBox.minHeightProperty().bind(stage.heightProperty()); rect.widthProperty().bind(vBox.widthProperty()); rect.heightProperty().bind(vBox.heightProperty().divide(3)); stage.setScene(new Scene(vBox)); stage.show();
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); scene.setRoot(new BuildLayout(stage)); Screen screen = Screen.getPrimary(); Rectangle2D bounds = screen.getVisualBounds(); stage.setTitle("Application Name"); stage.setScene(scene); stage.setX(bounds.getMinX()); stage.setY(bounds.getMinY()); stage.setWidth(bounds.getWidth()); stage.setHeight(bounds.getHeight()); stage.show(); }
titleContent.setOnMouseDragged(new EventHandler<MouseEvent>() { public void handle(MouseEvent mouseEvent) { Scene scene = (Scene) titleContent.getScene(); if (!(mouseEvent.getX() < border || mouseEvent.getX() > scene.getWidth() -border) && !(mouseEvent.getX() < border && mouseEvent.getY() > scene.getHeight() -border)){ Stage stage = (Stage) titleContent.getScene().getWindow(); Screen screen = Screen.getPrimary(); Rectangle2D bounds = screen.getVisualBounds(); if (stage.getWidth()==bounds.getMaxX() && stage.getHeight()==bounds.getMaxY()){ stage.setWidth(minWidth); stage.setHeight(minHeight); } stage.setX(mouseEvent.getScreenX() + dragDelta.x); stage.setY(mouseEvent.getScreenY() + dragDelta.y); } }
public void createDummyStage() { Stage dummyPopup = new Stage(); dummyPopup.initModality(Modality.NONE); // set as utility so no iconification occurs dummyPopup.initStyle(StageStyle.UTILITY); // set opacity so the window cannot be seen dummyPopup.setOpacity(0d); // not necessary, but this will move the dummy stage off the screen final Screen screen = Screen.getPrimary(); final Rectangle2D bounds = screen.getVisualBounds(); dummyPopup.setX(bounds.getMaxX()); dummyPopup.setY(bounds.getMaxY()); // create/add a transparent scene final Group root = new Group(); dummyPopup.setScene(new Scene(root, 1d, 1d, Color.TRANSPARENT)); // show the dummy stage dummyPopup.show(); }
/** * Under Windows, the undecorator Stage could be been dragged below the Task bar and then no way to * grab it again... On Mac, do not drag above the menu bar * * @param y */ void setStageY(Stage stage, double y) { try { ObservableList<Screen> screensForRectangle = Screen.getScreensForRectangle(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight()); if (screensForRectangle.size() > 0) { Screen screen = screensForRectangle.get(0); Rectangle2D visualBounds = screen.getVisualBounds(); if (y < visualBounds.getHeight() - 30 && y + SHADOW_WIDTH >= visualBounds.getMinY()) { stage.setY(y); } } } catch (Exception e) { e.printStackTrace(); } }
/** * Calculates the location of a window so that it will be centered on the screen. * * @param window the window * @return the location (top left corner) */ public Point2D determineCenteredLocation(Window window) { Rectangle2D screenSize = Screen.getPrimary().getVisualBounds(); // align sizes (for computation below) double windowWidth = window.getWidth(); double windowHeight = window.getHeight(); if (window.getWidth() > screenSize.getWidth()) { windowWidth = screenSize.getWidth(); } if (windowHeight > screenSize.getHeight()) { windowHeight = screenSize.getHeight(); } return new Point2D((screenSize.getWidth() - windowWidth) / 2.0, (screenSize.getHeight() - windowHeight) / 2.0); }
/** * Maximize and ajust the window to screen size. */ public void maximize() { Stage stage = undecorator.getStage(); ObservableList<Screen> screensForRectangle = Screen.getScreensForRectangle(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight()); Screen screen = screensForRectangle.get(0); Rectangle2D visualBounds = screen.getVisualBounds(); // save bounds before maximizing in order to restore later savedBounds = new BoundingBox(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight()); undecorator.setShadow(false); // effectivly maximize stage.setX(visualBounds.getMinX()); stage.setY(visualBounds.getMinY()); stage.setWidth(visualBounds.getWidth()); stage.setHeight(visualBounds.getHeight()); maximized = true; }