Screen screen = Screen.getScreensForRectangle(primaryStage.getX(), primaryStage.getY(), primaryStage.getWidth(), primaryStage.getHeight()).get(0); Rectangle2D bounds = screen.getVisualBounds(); maximizedBox = new BoundingBox(bounds.getMinX(), bounds.getMinY(),
private void fixPosition() { Window w = dialog.getOwner(); Screen s = com.sun.javafx.util.Utils.getScreen(w); Rectangle2D sb = s.getBounds(); double xR = w.getX() + w.getWidth(); double xL = w.getX() - dialog.getWidth(); double x; double y; if (sb.getMaxX() >= xR + dialog.getWidth()) { x = xR; } else if (sb.getMinX() <= xL) { x = xL; } else { x = Math.max(sb.getMinX(), sb.getMaxX() - dialog.getWidth()); } y = Math.max(sb.getMinY(), Math.min(sb.getMaxY() - dialog.getHeight(), w.getY())); dialog.setX(x); dialog.setY(y); }
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); }
double height = 600; try { Rectangle2D bounds = Screen.getScreens().get(0).getBounds(); width = bounds.getWidth() / 2.5; height = bounds.getHeight() / 1.35;
Screen screen = Screen.getPrimary(); Rectangle2D bounds = screen.getVisualBounds(); primaryStage.setX(bounds.getMinX()); primaryStage.setY(bounds.getMinY()); primaryStage.setWidth(bounds.getWidth()); primaryStage.setHeight(bounds.getHeight());
public static File captureScreenshot() { Path captureFile = Paths.get("screenshot" + new Date().getTime() + ".png"); Image captureImage = CAPTURE_SUPPORT.captureRegion(Screen.getPrimary().getBounds()); CAPTURE_SUPPORT.saveImage(captureImage, captureFile); return captureFile.toFile(); }
int newY = (int) (previousY + (previousHeight / 2.0) - (newHeight / 2.0)); ObservableList<Screen> screens = Screen.getScreensForRectangle(previousX, previousY, 1, 1); Screen screen = screens.isEmpty() ? Screen.getPrimary() : screens.get(0); Rectangle2D scrBounds = screen.getBounds(); int minX = (int)Math.round(scrBounds.getMinX()); int maxX = (int)Math.round(scrBounds.getMaxX());
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); } }
private boolean hasAvailableScreen(StageStatus status) { return !Screen.getScreensForRectangle(status.getX(), status.getY(), status.getWidth(), status.getHeight()) .isEmpty(); } }
Screen screen = Screen.getScreens().stream().filter(s->s.getBounds().contains(centerX,centerY)).findFirst().orElse(Screen.getPrimary()); Rectangle2D screenBounds = screen.getBounds(); pane.setPrefWidth(screenBounds.getWidth()/3); pane.setPrefHeight(screenBounds.getHeight()/2);
ObservableList<Screen> screens = Screen.getScreens(); for (Screen screen : screens) { Rectangle2D visualBounds = screen.getVisualBounds(); minX = Math.min(minX, visualBounds.getMinX()); minY = Math.min(minY, visualBounds.getMinY());
/** * Determine the pixels-per-inch of the screen we are on * @return */ double determinePPI() { if (ppi != null) { return ppi; } // Use command line value if (System.getProperties().containsKey(PPI_SYSTEM_PROPERTY)) { ppi = Double.valueOf(System.getProperty(PPI_SYSTEM_PROPERTY)); if (getTrace()) System.out.println("Using command line " + PPI_SYSTEM_PROPERTY + "=" + ppi); return ppi; } // determine the DPI factor, so the thresholds become larger on screens with a higher DPI ppi = 100.0; // average dpi Window window = getScene().getWindow(); ObservableList<Screen> screensForRectangle = Screen.getScreensForRectangle(window.getX(), window.getY(), window.getWidth(), window.getHeight()); if (screensForRectangle.size() > 0) { Screen lScreen = screensForRectangle.get(0); // we just use the first screen ppi = lScreen.getDpi(); if (getTrace()) System.out.println("screens of scene: " + screensForRectangle + ", using the first then PPI=" + ppi); } return ppi; } Double ppi;
public float calculateMaxRenderScale() { float maxRenderScale = 0; ScreenHelper.ScreenAccessor accessor = ScreenHelper.getScreenAccessor(); for (Screen screen : Screen.getScreens()) { maxRenderScale = Math.max(maxRenderScale, accessor.getRenderScale(screen)); } return maxRenderScale; }
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();
private static Object[] findInitialSize(String callee) { final Preferences prefs = Preferences.userRoot().node(callee.replace('.', '/')); Rectangle2D screen = Screen.getPrimary().getBounds(); double x = prefs.getDouble("x", screen.getWidth() * 0.05); // NOI18N double y = prefs.getDouble("y", screen.getHeight() * 0.05); // NOI18N double width = prefs.getDouble("width", screen.getWidth() * 0.9); // NOI18N double height = prefs.getDouble("height", screen.getHeight() * 0.9); // NOI18N Object[] arr = { x, y, width, height, null }; if (!callee.equals("org.netbeans.html")) { // NOI18N arr[4] = new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent event) { Window window = (Window) event.getSource(); prefs.putDouble("x", window.getX()); // NOI18N prefs.putDouble("y", window.getY()); // NOI18N prefs.putDouble("width", window.getWidth()); // NOI18N prefs.putDouble("height", window.getHeight()); // NOI18N } }; } return arr; }
@Override public void afterLoad() { if(Screen.getScreensForRectangle(x, y, x+1, y+1).isEmpty()) { x = DEFAULT_X; y = DEFAULT_Y; } }
/** * 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(); } }
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); }
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);
private void _resize(final double width, final double height) { Window window = container.getScene().getWindow(); // size difference between root node and window depends on OS and Decorations double diffY = window.getHeight() - container.getHeight(); double diffX = window.getWidth() - container.getWidth(); webView.setMaxWidth(width); webView.setMaxHeight(height); webView.setMinWidth(width); webView.setMinHeight(height); javafx.geometry.Rectangle2D screenBounds = Screen.getPrimary().getBounds(); double scaleX = screenBounds.getWidth() / ( width + diffX ); double scaleY = screenBounds.getHeight() / ( height + diffY ); // calculate scale factor if too big for device, the .1 adds some padding double scale = Math.min(Math.min(scaleX, scaleY), 1.1) - .1; webView.setScaleX(scale); webView.setScaleY(scale); container.getScene().setRoot(new Group()); ((Stage)window).setScene(new Scene(container, width * scale, height * scale)); }