Java Code Examples for javafx.stage.Screen#getVisualBounds()
The following examples show how to use
javafx.stage.Screen#getVisualBounds() .
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 |
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: UndecoratorController.java From DevToolBox with GNU Lesser General Public License v2.1 | 6 votes |
/** * Based on mouse position returns dock side * * @param mouseEvent * @return DOCK_LEFT,DOCK_RIGHT,DOCK_TOP */ int getDockSide(MouseEvent mouseEvent) { double minX = Double.POSITIVE_INFINITY; double minY = Double.POSITIVE_INFINITY; double maxX = 0; double maxY = 0; // Get "big" screen bounds 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()); maxX = Math.max(maxX, visualBounds.getMaxX()); maxY = Math.max(maxY, visualBounds.getMaxY()); } // Dock Left if (mouseEvent.getScreenX() == minX) { return DOCK_LEFT; } else if (mouseEvent.getScreenX() >= maxX - 1) { // MaxX returns the width? Not width -1 ?! return DOCK_RIGHT; } else if (mouseEvent.getScreenY() <= minY) { // Mac menu bar return DOCK_TOP; } return 0; }
Example 3
Source File: HostelProject.java From Hostel-Management-System with MIT License | 6 votes |
@Override public void start(Stage stage) throws SQLException, IOException { Parent root = FXMLLoader.load(getClass().getResource("MainScene.fxml")); scene = new Scene(root); Screen screen = Screen.getPrimary(); Rectangle2D bounds = screen.getVisualBounds(); Image ico=new Image("file:///D:/Study/Java/HostelProjecttest/src/hostelproject/media/net.png"); stage.setTitle("Banda Singh Bahadur Boys Hostel"); stage.getIcons().add(ico); stage.setX(bounds.getMinX()); stage.setY(bounds.getMinY()); stage.setWidth(bounds.getWidth()); stage.setHeight(bounds.getHeight()); stage.setScene(scene); stage.show(); }
Example 4
Source File: EnvironmentManagerImpl.java From VocabHunter with Apache License 2.0 | 6 votes |
@Override public boolean isVisible(final Placement placement) { ObservableList<Screen> screens = Screen.getScreensForRectangle(rectangle(placement)); if (screens.size() == 1) { Screen screen = screens.get(0); Rectangle2D bounds = screen.getVisualBounds(); if (placement.isPositioned()) { return bounds.contains(placement.getX(), placement.getY(), placement.getWidth(), placement.getHeight()); } else { return bounds.getWidth() >= placement.getWidth() && bounds.getHeight() >= placement.getHeight(); } } else { return false; } }
Example 5
Source File: SplashStage.java From Quelea with GNU General Public License v3.0 | 5 votes |
/** * Create a new splash window. */ public SplashStage() { initModality(Modality.APPLICATION_MODAL); initStyle(StageStyle.UNDECORATED); Utils.addIconsToStage(this); setTitle("Quelea " + LabelGrabber.INSTANCE.getLabel("loading.text") + "..."); Image splashImage = new Image(new File(QueleaProperties.VERSION.getUnstableName().getSplashPath()).getAbsoluteFile().toURI().toString()); ImageView imageView = new ImageView(splashImage); Group mainPane = new Group(); mainPane.getChildren().add(imageView); Scene scene = new Scene(mainPane); if (QueleaProperties.get().getUseDarkTheme()) { scene.getStylesheets().add("org/modena_dark.css"); } setScene(scene); ObservableList<Screen> monitors = Screen.getScreens(); Screen screen; int controlScreenProp = QueleaProperties.get().getControlScreen(); if (controlScreenProp < monitors.size() && controlScreenProp >= 0) { screen = monitors.get(controlScreenProp); } else { screen = Screen.getPrimary(); } Rectangle2D bounds = screen.getVisualBounds(); setX(bounds.getMinX() + ((bounds.getWidth() / 2) - splashImage.getWidth() / 2)); setY(bounds.getMinY() + ((bounds.getHeight() / 2) - splashImage.getHeight() / 2)); }
Example 6
Source File: UndecoratorController.java From DevToolBox with GNU Lesser General Public License v2.1 | 5 votes |
/** * 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) { Undecorator.LOGGER.log(Level.SEVERE, "setStageY issue", e); } }
Example 7
Source File: ScreenUtil.java From phoebus with Eclipse Public License 1.0 | 5 votes |
/** @param x Screen coordinates * @param y Screen coordinates * @return Bounds of screen that contains the point, or <code>null</code> if no screen found */ public static Rectangle2D getScreenBounds(final double x, final double y) { for (Screen screen : Screen.getScreens()) { final Rectangle2D check = screen.getVisualBounds(); // contains(x, y) would include the right edge if (x >= check.getMinX() && x < check.getMaxX() && y >= check.getMinY() && y < check.getMaxY()) return check; } return null; }
Example 8
Source File: Main.java From greenbeans with Apache License 2.0 | 5 votes |
private void setSizeAndLocation(Stage primaryStage) { Screen primaryScreen = Screen.getPrimary(); Rectangle2D visualBounds = primaryScreen.getVisualBounds(); primaryStage.setWidth(Math.min(Constants.DEFAULT_WIDTH, visualBounds.getWidth())); primaryStage.setHeight(Math.min(Constants.DEFAULT_HEIGHT, visualBounds.getHeight())); }
Example 9
Source File: FX.java From FxDock with Apache License 2.0 | 5 votes |
/** returns true if the coordinates belong to one of the Screens */ public static boolean isValidCoordinates(double x, double y) { for(Screen screen: Screen.getScreens()) { Rectangle2D r = screen.getVisualBounds(); if(r.contains(x, y)) { return true; } } return false; }
Example 10
Source File: DockNode.java From DockFX with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected void invalidated() { DockNode.this.pseudoClassStateChanged(MAXIMIZED_PSEUDO_CLASS, get()); if (borderPane != null) { borderPane.pseudoClassStateChanged(MAXIMIZED_PSEUDO_CLASS, get()); } stage.setMaximized(get()); // TODO: This is a work around to fill the screen bounds and not overlap the task bar when // the window is undecorated as in Visual Studio. A similar work around needs applied for // JFrame in Swing. http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4737788 // Bug report filed: // https://bugs.openjdk.java.net/browse/JDK-8133330 if (this.get()) { Screen screen = Screen .getScreensForRectangle(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight()) .get(0); Rectangle2D bounds = screen.getVisualBounds(); stage.setX(bounds.getMinX()); stage.setY(bounds.getMinY()); stage.setWidth(bounds.getWidth()); stage.setHeight(bounds.getHeight()); } }
Example 11
Source File: StartUpLocation.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Get Top Left X and Y Positions for a Window to centre it on the * currently active screen at application startup * @param windowWidth - Window Width * @param windowHeight - Window Height */ public StartUpLocation(double windowWidth, double windowHeight) { //System.out.println("(" + windowWidth + ", " + windowHeight + ")"); // Get X Y of start-up location on Active Screen // simple_JavaFX_App try { // Get current mouse location, could return null if mouse is moving Super-Man fast Point p = MouseInfo.getPointerInfo().getLocation(); // Get list of available screens List<Screen> screens = Screen.getScreens(); if (p != null && screens != null && screens.size() > 1) { // in order for xPos != 0 and yPos != 0 in startUpLocation, there has to be more than 1 screen // Screen bounds as rectangle Rectangle2D screenBounds; // Go through each screen to see if the mouse is currently on that screen for (Screen screen : screens) { screenBounds = screen.getVisualBounds(); // Trying to compute Left Top X-Y position for the Applcation Window // If the Point p is in the Bounds if (screenBounds.contains(p.x, p.y)) { // Fixed Size Window Width and Height xPos = screenBounds.getMinX() + ((screenBounds.getMaxX() - screenBounds.getMinX() - windowWidth) / 2); yPos = screenBounds.getMinY() + ((screenBounds.getMaxY() - screenBounds.getMinY() - windowHeight) / 2); return; } } } } catch (HeadlessException headlessException) { // Catch and report exceptions headlessException.printStackTrace(); } }
Example 12
Source File: MainMenu.java From mars-sim with GNU General Public License v3.0 | 4 votes |
public MainMenu() { // logger.config("MainMenu's constructor is on " + // Thread.currentThread().getName()); mainMenu = this; IconFontFX.register(FontAwesome.getIconFont()); // See DPI Scaling at // http://news.kynosarges.org/2015/06/29/javafx-dpi-scaling-fixed/ // "I guess we'll have to wait until Java 9 for more flexible DPI support. // In the meantime I managed to get JavaFX DPI scale factor, // but it is a hack (uses both AWT and JavaFX methods)" // // Number of actual horizontal lines (768p) // double trueHorizontalLines = Toolkit.getDefaultToolkit().getScreenSize().getHeight(); // // Number of scaled horizontal lines. (384p for 200%) // double scaledHorizontalLines = Screen.getPrimary().getBounds().getHeight(); // // DPI scale factor. // double dpiScaleFactor = trueHorizontalLines / scaledHorizontalLines; // // logger.config("horizontal lines : " + trueHorizontalLines); // logger.config("DPI Scale Factor is " + dpiScaleFactor); Screen screen = Screen.getPrimary(); Rectangle2D bounds = screen.getVisualBounds(); // getBounds();// native_width = (int) bounds.getWidth(); native_height = (int) bounds.getHeight(); // Detect the current native screen resolution // mainscene_height = native_height; // mainscene_width = native_width; // Assume the typical laptop screen resolution. Will change it later all // modifications are done mainscene_height = HEIGHT; mainscene_width = WIDTH; setupResolutions(); logger.config("Current Screen Resolution is " + native_width + " x " + native_height); // Note : Testing only // logger.config("Earth's surface gravity : " + // Math.round(PlanetType.EARTH.getSurfaceGravity()*100.0)/100.0 + " m/s^2"); // logger.config("Mars's surface gravity : " + // Math.round(PlanetType.MARS.getSurfaceGravity()*100.0)/100.0 + " m/s^2"); }
Example 13
Source File: JFXDecorator.java From JFoenix with Apache License 2.0 | 4 votes |
private void maximize(SVGGlyph resizeMin, SVGGlyph resizeMax) { if (!isCustomMaximize()) { primaryStage.setMaximized(!primaryStage.isMaximized()); maximized = primaryStage.isMaximized(); if (primaryStage.isMaximized()) { btnMax.setGraphic(resizeMin); btnMax.setTooltip(new Tooltip("Restore Down")); } else { btnMax.setGraphic(resizeMax); btnMax.setTooltip(new Tooltip("Maximize")); } } else { if (!maximized) { // store original bounds originalBox = new BoundingBox(primaryStage.getX(), primaryStage.getY(), primaryStage.getWidth(), primaryStage.getHeight()); // get the max stage bounds 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(), bounds.getWidth(), bounds.getHeight()); // maximized the stage primaryStage.setX(maximizedBox.getMinX()); primaryStage.setY(maximizedBox.getMinY()); primaryStage.setWidth(maximizedBox.getWidth()); primaryStage.setHeight(maximizedBox.getHeight()); btnMax.setGraphic(resizeMin); btnMax.setTooltip(new Tooltip("Restore Down")); } else { // restore stage to its original size primaryStage.setX(originalBox.getMinX()); primaryStage.setY(originalBox.getMinY()); primaryStage.setWidth(originalBox.getWidth()); primaryStage.setHeight(originalBox.getHeight()); originalBox = null; btnMax.setGraphic(resizeMax); btnMax.setTooltip(new Tooltip("Maximize")); } maximized = !maximized; } }
Example 14
Source File: PopOver.java From logbook-kai with MIT License | 4 votes |
/** * ポップアップの表示位置を設定します * * @param popup ポップアップ * @param anchorNode アンカーノード * @param event {@link MouseEvent} */ protected void setLocation(Popup popup, Node anchorNode, MouseEvent event) { double x = event.getScreenX(); double y = event.getScreenY(); double width = popup.getWidth(); double height = popup.getHeight(); double gapSize = this.getGapSize(); PopupWindow.AnchorLocation anchorLocation = PopupWindow.AnchorLocation.CONTENT_TOP_LEFT; double gapX = gapSize; double gapY = gapSize; for (Screen screen : Screen.getScreens()) { Rectangle2D screenRect = screen.getVisualBounds(); // 右下 に表示可能であれば if (screenRect.contains(x + gapSize, y + gapSize, width, height)) { // PopupWindow視点でアンカーノードがTOP_LEFTの位置 anchorLocation = PopupWindow.AnchorLocation.CONTENT_TOP_LEFT; gapX = gapSize; gapY = gapSize; break; } // 左下 if (screenRect.contains(x - gapSize - width, y + gapSize, width, height)) { anchorLocation = PopupWindow.AnchorLocation.CONTENT_TOP_RIGHT; gapX = -gapSize; gapY = gapSize; break; } // 右上 if (screenRect.contains(x + gapSize, y - gapSize - height, width, height)) { anchorLocation = PopupWindow.AnchorLocation.CONTENT_BOTTOM_LEFT; gapX = gapSize; gapY = -gapSize; break; } // 左上 if (screenRect.contains(x - gapSize - width, y - gapSize - height, width, height)) { anchorLocation = PopupWindow.AnchorLocation.CONTENT_BOTTOM_RIGHT; gapX = -gapSize; gapY = -gapSize; break; } } popup.setAnchorLocation(anchorLocation); popup.setAnchorX(x + gapX); popup.setAnchorY(y + gapY); }