double height = 600; try { Rectangle2D bounds = Screen.getScreens().get(0).getBounds(); width = bounds.getWidth() / 2.5; height = bounds.getHeight() / 1.35;
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); }
Screen screen = Screen.getPrimary(); Rectangle2D sbounds = screen.getBounds(); double sw = sbounds.getWidth() ; double sh = sbounds.getHeight(); listenToSizeInitialization(primaryStage.widthProperty(), w -> primaryStage.setX(( sw - w) /2)); listenToSizeInitialization(primaryStage.heightProperty(), h -> primaryStage.setY(( sh - h) /2)); primaryStage.show();
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 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)screen.getBounds().getMinX(), (int)screen.getBounds().getMinY(), (int)screen.getBounds().getWidth(), (int)screen.getBounds().getHeight(), true ); WritableImage dskTop = new WritableImage((int)screen.getBounds().getWidth(), (int)screen.getBounds().getHeight()); dskTop.getPixelWriter().setPixels( (int)screen.getBounds().getMinX(), (int)screen.getBounds().getMinY(), (int)screen.getBounds().getWidth(), (int)screen.getBounds().getHeight(), PixelFormat.getByteBgraPreInstance(), p.asByteBuffer(), (int)(screen.getBounds().getWidth() * 4) );
/** * 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; }
Scene scene = new Scene(root); primaryStage.setScene(scene); Rectangle2D bounds = primaryScreen.getBounds(); primaryStage.setX(bounds.getMinX()); primaryStage.setY(bounds.getMinY()); Scene scene2 = new Scene(root2); secondaryStage.setScene(scene2); Rectangle2D bounds2 = secondaryScreen.getBounds(); secondaryStage.setX(bounds2.getMinX()); secondaryStage.setY(bounds2.getMinY());
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; }
Rectangle2D screenBounds = screen.getBounds(); double xSize = screenBounds.getWidth(); double ySize = screenBounds.getHeight();
double maxX = screen.getBounds().getMaxX();
Rectangle2D scrBounds = screen.getBounds(); int minX = (int)Math.round(scrBounds.getMinX()); int maxX = (int)Math.round(scrBounds.getMaxX());
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); }
double maxY = Double.NEGATIVE_INFINITY ; for (Screen screen : Screen.getScreens()) { Rectangle2D screenBounds = screen.getBounds(); if (screenBounds.getMinX() < minX) { minX = screenBounds.getMinX();
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)); }