Java Code Examples for javafx.stage.Stage#getY()

The following examples show how to use javafx.stage.Stage#getY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StageControllerImpl.java    From scenic-view with GNU General Public License v3.0 6 votes vote down vote up
public void placeStage(final Stage stage) {
    if (targetWindow != null) {
        stage.setX(targetWindow.getX() + targetWindow.getWidth());
        stage.setY(targetWindow.getY());
        try {
            // Prevents putting the stage out of the screen
            final Screen primary = Screen.getPrimary();
            if (primary != null) {
                final Rectangle2D rect = primary.getVisualBounds();
                if (stage.getX() + stage.getWidth() > rect.getMaxX()) {
                    stage.setX(rect.getMaxX() - stage.getWidth());
                }
                if (stage.getY() + stage.getHeight() > rect.getMaxY()) {
                    stage.setX(rect.getMaxY() - stage.getHeight());
                }
            }
        } catch (final Exception e) {
            ExceptionLogger.submitException(e);
        }
    }
}
 
Example 2
Source File: CrewEditorFX.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
private Image copyBackground(Stage stage) {
	final int X = (int) stage.getX();
	final int Y = (int) stage.getY();
	final int W = (int) stage.getWidth();
	final int H = (int) stage.getHeight();

	try {
		java.awt.Robot robot = new java.awt.Robot();
		java.awt.image.BufferedImage image = robot.createScreenCapture(new java.awt.Rectangle(X, Y, W, H));

		return SwingFXUtils.toFXImage(image, null);
	} catch (java.awt.AWTException e) {
		System.out.println("The robot of doom strikes!");
		e.printStackTrace();

		return null;
	}
}
 
Example 3
Source File: FrostyTech.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
private Image copyBackground(Stage stage) {
    final int X = (int) stage.getX();
    final int Y = (int) stage.getY();
    final int W = (int) stage.getWidth();
    final int H = (int) stage.getHeight();

    try {
        java.awt.Robot robot = new java.awt.Robot();
        java.awt.image.BufferedImage image = robot.createScreenCapture(new java.awt.Rectangle(X, Y, W, H));

        return SwingFXUtils.toFXImage(image, null);
    } catch (java.awt.AWTException e) {
        System.out.println("The robot of doom strikes!");
        e.printStackTrace();

        return null;
    }
}
 
Example 4
Source File: AboutController.java    From Animu-Downloaderu with MIT License 5 votes vote down vote up
@FXML private void donate() {
	var dialog = new DonateDialog();
	Stage stage = (Stage) root.getScene().getWindow(); // an ugly way of initializing stage
	// Calculate the center position of the parent Stage
	double centerXPosition = stage.getX() + stage.getWidth() / 2d;
	double centerYPosition = stage.getY() + stage.getHeight() / 2d;

	dialog.setOnShowing(e -> {
		dialog.setX(centerXPosition - dialog.getDialogPane().getWidth() / 2d);
		dialog.setY(centerYPosition - dialog.getDialogPane().getHeight() / 2d);
	});

	dialog.showAndWait();
}
 
Example 5
Source File: WindowSettingsParameter.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Set window size and position according to the values in this instance
 */
public void applySettingsToWindow(@Nonnull final Stage stage) {

  logger.finest("Setting window " + stage.getTitle() + " position " + posX + ":" + posY
      + " and size " + width + "x" + height);
  if (posX != null)
    stage.setX(posX);
  if (posY != null)
    stage.setX(posY);
  if (width != null)
    stage.setWidth(width);
  if (height != null)
    stage.setHeight(height);

  if ((isMaximized != null) && isMaximized) {
    logger.finest("Setting window " + stage.getTitle() + " to maximized");
    stage.setMaximized(true);
  }

  // when still outside of screen
  // e.g. changing from 2 screens to one
  if (stage.isShowing() && !isOnScreen(stage)) {
    // Maximize on screen 1
    logger.finest(
        "Window " + stage.getTitle() + " is not on screen, setting to maximized on screen 1");
    stage.setX(0.0);
    stage.setY(0.0);
    stage.sizeToScene();
    stage.setMaximized(true);
  }

  ChangeListener<Number> stageListener = (observable, oldValue, newValue) -> {
    posX = stage.getX();
    posY = stage.getY();
    width = stage.getWidth();
    height = stage.getHeight();
  };
  stage.widthProperty().addListener(stageListener);
  stage.heightProperty().addListener(stageListener);
  stage.xProperty().addListener(stageListener);
  stage.yProperty().addListener(stageListener);

}
 
Example 6
Source File: WindowSettingsParameter.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
private boolean isOnScreen(Stage stage) {
  Rectangle2D stagePosition =
      new Rectangle2D(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight());
  var screens = Screen.getScreensForRectangle(stagePosition);
  return !screens.isEmpty();
}
 
Example 7
Source File: HelpBox.java    From scenic-view with GNU General Public License v3.0 4 votes vote down vote up
public static HelpBox make(final String title, final String url, final Stage stage) {
    DisplayUtils.showWebView(true);
    final HelpBox node = new HelpBox(title, url, stage.getX() + (stage.getWidth() / 2) - (SCENE_WIDTH / 2), stage.getY() + (stage.getHeight() / 2) - (SCENE_HEIGHT / 2));
    return node;
}
 
Example 8
Source File: UndecoratorController.java    From DevToolBox with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void saveBounds() {
    Stage stage = undecorator.getStage();
    savedBounds = new BoundingBox(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight());
}
 
Example 9
Source File: UndecoratorController.java    From DevToolBox with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void saveFullScreenBounds() {
    Stage stage = undecorator.getStage();
    savedFullScreenBounds = new BoundingBox(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight());
}
 
Example 10
Source File: Dialog.java    From LogFX with GNU General Public License v3.0 4 votes vote down vote up
StageTranslateTransition( Stage stage ) {
    this.stage = stage;
    this.originalY = stage.getY();
}