@Override public void invalidated(Observable ignored) { if (Double.isNaN(dialog.getWidth()) || Double.isNaN(dialog.getHeight())) { return; } dialog.widthProperty().removeListener(positionAdjuster); dialog.heightProperty().removeListener(positionAdjuster); fixPosition(); } };
@Override public void layoutChildren() { super.layoutChildren(); if (dialog.getMinWidth() > 0 && dialog.getMinHeight() > 0) { return; } double minWidth = Math.max(0, computeMinWidth(getHeight()) + (dialog.getWidth() - customScene.getWidth())); double minHeight = Math.max(0, computeMinHeight(getWidth()) + (dialog.getHeight() - customScene.getHeight())); dialog.setMinWidth(minWidth); dialog.setMinHeight(minHeight); } }
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); } }); }
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); }
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); } }
public class ChatWindow extends Application { @Override public void start(final Stage stage) throws Exception { stage.initStyle(StageStyle.TRANSPARENT); // here it is Group rg = new Group(); Scene scene = new Scene(rg, 320, 240, Color.TRANSPARENT); stage.setScene(scene); stage.show(); Rectangle r = new Rectangle(5, 5, stage.getWidth() - 10, stage.getHeight() - 10); r.setFill(Color.STEELBLUE); r.setEffect(new DropShadow()); rg.getChildren().add(r); } public static void main(String[] args) { launch(); } }
imageView.setImage(image); imageView.setStyle("-fx-background-color: BLACK"); imageView.setFitHeight(stage.getHeight() - 10); imageView.setPreserveRatio(true); imageView.setSmooth(true); Stage newStage = new Stage(); newStage.setWidth(stage.getWidth()); newStage.setHeight(stage.getHeight()); newStage.setTitle(imageFile.getName()); Scene scene = new Scene(borderPane,Color.BLACK);
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); }
@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(); }
/** * {@inheritDoc} */ @Override public Dimension remoteGetSize() { return AppThread.exec(() -> new Dimension((int) Math.rint((Double) stage.get().getWidth()), (int) Math.rint((Double) stage.get().getHeight()))); }
@Override public void invalidated(Observable ignored) { if (Double.isNaN(dialog.getWidth()) || Double.isNaN(dialog.getHeight())) { return; } dialog.widthProperty().removeListener(positionAdjuster); dialog.heightProperty().removeListener(positionAdjuster); fixPosition(); } };
protected void mouseDragged(MouseEvent event) { if (!dragging) { return; } double mousey = event.getY(); stage.setHeight(stage.getY() - event.getScreenY() + 20 + stage.getHeight()); y = mousey; }
final Stage dialog = new Stage(); dialog.initOwner(window); dialog.initModality(Modality.WINDOW_MODAL); dialog.sizeToScene(); dialog.setScene(scene); Platform.runLater(new Runnable() { @Override public void run() { dialog.setX(primaryStage.getX() + primaryStage.getWidth() / 2 - dialog.getWidth() / 2); //dialog.getWidth() = NaN dialog.setY(primaryStage.getY() + primaryStage.getHeight() / 2 - dialog.getHeight() / 2); //dialog.getHeight() = NaN } }); dialog.showAndWait();
/** * 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 saveFullScreenBounds() { Stage stage = undecorator.getStage(); savedFullScreenBounds = new BoundingBox(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight()); }
public void saveBounds() { Stage stage = undecorator.getStage(); savedBounds = new BoundingBox(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight()); }
@Override public void layoutChildren() { super.layoutChildren(); if (dialog.getMinWidth() > 0 && dialog.getMinHeight() > 0) { return; } double minWidth = Math.max(0, computeMinWidth(getHeight()) + (dialog.getWidth() - customScene.getWidth())); double minHeight = Math.max(0, computeMinHeight(getWidth()) + (dialog.getHeight() - customScene.getHeight())); dialog.setMinWidth(minWidth); dialog.setMinHeight(minHeight); } }
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(); }