private void updateInitMouseValues(MouseEvent mouseEvent) { initStageX = primaryStage.getX(); initStageY = primaryStage.getY(); initWidth = primaryStage.getWidth(); initHeight = primaryStage.getHeight(); initX = mouseEvent.getScreenX(); initY = mouseEvent.getScreenY(); xOffset = mouseEvent.getSceneX(); yOffset = mouseEvent.getSceneY(); }
/** * Adds an OnCloseRequest handle to the window which will store the position, * size and maximized status of the window. * * @param stage the stage to read settings from * @param name the name under which we store the settings */ public static void applySaveOnCloseMethod(Stage stage, String name){ stage.setOnCloseRequest( ev -> { try { Preferences stagePreferences = PREFERENCES.node(name); if( stage.isMaximized() ){ stagePreferences.putBoolean(WINDOW_MAXIMIZED, true); } else { stagePreferences.putBoolean(WINDOW_MAXIMIZED, false); stagePreferences.putDouble(WINDOW_X_POS, stage.getX()); stagePreferences.putDouble(WINDOW_Y_POS, stage.getY()); stagePreferences.putDouble(WINDOW_WIDTH, stage.getWidth()); stagePreferences.putDouble(WINDOW_HEIGHT, stage.getHeight()); } stagePreferences.flush(); } catch (final BackingStoreException ex) { LOGGER.error(ex, "Could not flush preferences for window " + name); } }); }
public class CenterStage extends Application { @Override public void start(final Stage stage) throws Exception { stage.setX(300); stage.setWidth(800); stage.setHeight(400); stage.show(); final Stage childStage = new Stage(); childStage.setWidth(200); childStage.setHeight(200); childStage.setX(stage.getX() + stage.getWidth() / 2 - childStage.getWidth() / 2); childStage.setY(stage.getY() + stage.getHeight() / 2 - childStage.getHeight() / 2); childStage.show(); } public static void main(String[] args) { Application.launch(args); } }
@Override public void stop() { LOG.info(DefaultI18nContext.getInstance().i18n("Closing PDFsam...")); if (nonNull(primaryStage)) { StageStatus status = new StageStatus(this.primaryStage.getX(), this.primaryStage.getY(), this.primaryStage.getWidth(), this.primaryStage.getHeight()); status.setMode(StageMode.valueFor(this.primaryStage)); eventStudio().broadcast(new SetLatestStageStatusRequest(status)); } saveWorkspaceIfRequired(); eventStudio().broadcast(new ShutdownEvent()); injector.close(); }
@Override public void handle(MouseEvent mouseEvent) { dragDelta.x = stage.getX() - mouseEvent.getScreenX(); dragDelta.y = stage.getY() - mouseEvent.getScreenY(); byNode.setCursor(Cursor.MOVE);
Stage stage = (Stage) scene.getWindow(); stage.toFront(); Rectangle sceneRect = new Rectangle( stage.getX() + scene.getX(), stage.getY() + scene.getY(), scene.getWidth(), scene.getHeight());
/** * {@inheritDoc} */ @Override public Point remoteGetPosition() { return AppThread.exec(() -> new Point((int) Math.rint((Double) stage.get().getX()), (int) Math.rint((Double) stage.get().getY()))); }
double windowGap = 5 ; Stage currentStage = ... ; // the current window... stage.setX(currentStage.getX() + currentStage.getWidth() + windowGap); stage.setY(currentStage.getY());
@FXML private AnchorPane ap; Stage stage = (Stage) ap.getScene().getWindow(); File file = new File("snapshot.png"); try { Rectangle rectangle = new Rectangle((int)stage.getX(), (int)stage.getY(), (int)stage.getWidth(), (int)stage.getHeight()); BufferedImage bufferedImage = new Robot().createScreenCapture(rectangle); ImageIO.write(bufferedImage, "png", file); } catch (IOException ex) { //IOException } catch (AWTException ex) { //AWTException }
void mouseMove(final double viewportX, final double viewportY) { lock(); try { AppThread.exec(context.item().statusCode, () -> { Stage stage = context.item().stage.get(); double adjustedX = Math.max(0, Math.min(viewportX, stage.getScene().getWidth() - 1)); double adjustedY = Math.max(0, Math.min(viewportY, stage.getScene().getHeight() - 1)); robot.get().mouseMove( (int) Math.rint(adjustedX + (Double) stage.getX() + (Double) stage.getScene().getX()), (int) Math.rint(adjustedY + (Double) stage.getY() + (Double) stage.getScene().getY())); return null; }); } finally { unlock(); } }
/** * The bounds of the dialog * <p> * <b>Has to be called after {@link #open()}.</b> * </p> * * @return the current bounds of the dialog window */ public @NonNull Rectangle getBounds() { return new Rectangle(this.stage.getX(), this.stage.getY(), this.stage.getWidth(), this.stage.getHeight()); }
public void saveBounds() { Stage stage = undecorator.getStage(); savedBounds = new BoundingBox(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight()); }
public void saveFullScreenBounds() { Stage stage = undecorator.getStage(); savedFullScreenBounds = new BoundingBox(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight()); }
public static final class Utils { public static Stage getStage() { return StageHelper.getStages().get(0); } public static void centre(Dialog dialog) { Window window = dialog.getWindow(); Stage scene = Utils.getStage(); double x = scene.getX() + scene.getWidth() / 2 - window.getWidth() / 2; double y = scene.getY() + scene.getHeight() / 2 - window.getHeight() / 2; window.setX(x); window.setY(y); } } ... Platform.runLater(() -> { Utils.centre(dialog); } dialog.show();
private void updateInitMouseValues(MouseEvent mouseEvent) { initStageX = primaryStage.getX(); initStageY = primaryStage.getY(); initWidth = primaryStage.getWidth(); initHeight = primaryStage.getHeight(); initX = mouseEvent.getScreenX(); initY = mouseEvent.getScreenY(); xOffset = mouseEvent.getSceneX(); yOffset = mouseEvent.getSceneY(); }
/** * 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(); } }
/** * Maximize the window */ protected void maximize() { // We are bound to the stage if (!isLightweight()) { Stage stage = getStage(); final double stageY = stage.getY(); final Screen screen = Screen.getScreensForRectangle(stage.getX(), stageY, 1, 1).get(0); this.backupWindowBounds = new Rectangle2D(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight()); final double newStageY = screen.getVisualBounds().getMinY(); stage.setX(screen.getVisualBounds().getMinX()); stage.setY(newStageY); stage.setWidth(screen.getVisualBounds().getWidth()); stage.setHeight(screen.getVisualBounds().getHeight()); getStyleClass().add("window-maximized"); //$NON-NLS-1$ // stage.setMaximized(true); this.maximized.set(true); } else { // We are embedded into a container do nothing } }
/** * Maximize the window */ protected void maximize() { // We are bound to the stage if (!isLightweight()) { Stage stage = getStage(); final double stageY = stage.getY(); final Screen screen = Screen.getScreensForRectangle(stage.getX(), stageY, 1, 1).get(0); this.backupWindowBounds = new Rectangle2D(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight()); final double newStageY = screen.getVisualBounds().getMinY(); stage.setX(screen.getVisualBounds().getMinX()); stage.setY(newStageY); stage.setWidth(screen.getVisualBounds().getWidth()); stage.setHeight(screen.getVisualBounds().getHeight()); getStyleClass().add("window-maximized"); //$NON-NLS-1$ // stage.setMaximized(true); this.maximized.set(true); } else { // We are embedded into a container do nothing } }
/** * 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; }