本文整理汇总了Java中javafx.stage.Screen.getBounds方法的典型用法代码示例。如果您正苦于以下问题:Java Screen.getBounds方法的具体用法?Java Screen.getBounds怎么用?Java Screen.getBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.stage.Screen
的用法示例。
在下文中一共展示了Screen.getBounds方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: centerDialogOnScreen
import javafx.stage.Screen; //导入方法依赖的package包/类
/**
* Utility method to center a Dialog/Alert on the middle of the current
* screen. Used to workaround a "bug" with the current version of JavaFX (or
* the SWT/JavaFX embedding?) where alerts always show on the primary
* screen, not necessarily the current one.
*
* @param dialog
* The dialog to reposition. It must be already shown, or else
* this will do nothing.
* @param referenceNode
* The dialog should be moved to the same screen as this node's
* window.
*/
public static void centerDialogOnScreen(Dialog<?> dialog, Node referenceNode) {
Window window = referenceNode.getScene().getWindow();
if (window == null) {
return;
}
Rectangle2D windowRectangle = new Rectangle2D(window.getX(), window.getY(), window.getWidth(), window.getHeight());
List<Screen> screens = Screen.getScreensForRectangle(windowRectangle);
Screen screen = screens.stream()
.findFirst()
.orElse(Screen.getPrimary());
Rectangle2D screenBounds = screen.getBounds();
dialog.setX((screenBounds.getWidth() - dialog.getWidth()) / 2 + screenBounds.getMinX());
// dialog.setY((screenBounds.getHeight() - dialog.getHeight()) / 2 + screenBounds.getMinY());
}
示例2: getDesktopSize
import javafx.stage.Screen; //导入方法依赖的package包/类
static Rectangle2D getDesktopSize() {
Rectangle2D rect = Screen.getPrimary().getBounds();
double minX = rect.getMinX(), minY = rect.getMinY();
double maxX = rect.getMaxX(), maxY = rect.getMaxY();
for (Screen screen : Screen.getScreens()) {
Rectangle2D screenRect = screen.getBounds();
if (minX > screenRect.getMinX()) {
minX = screenRect.getMinX();
}
if (minY > screenRect.getMinY()) {
minY = screenRect.getMinY();
}
if (maxX < screenRect.getMaxX()) {
maxX = screenRect.getMaxX();
}
if (maxY < screenRect.getMaxY()) {
maxY = screenRect.getMaxY();
}
}
return new Rectangle2D(minX, minY, maxX - minX, maxY - minY);
}
示例3: fixPosition
import javafx.stage.Screen; //导入方法依赖的package包/类
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, 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);
}
示例4: start
import javafx.stage.Screen; //导入方法依赖的package包/类
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
Screen screen = Screen.getPrimary();
Rectangle2D screenBounds = screen.getBounds();
primaryStage.setWidth(screenBounds.getWidth() * 0.95);
primaryStage.setHeight(screenBounds.getHeight() * 0.90);
primaryStage.setMaximized(false);
homeMenuScreen = HomeMenuScreen.newInstance(this, ConfigurationBuilder.createFromPropertiesResource().build());
homeMenuScreen.setUpOnStage(primaryStage);
primaryStage.centerOnScreen();
primaryStage.setFullScreen(true);
}
示例5: setArenaScreenOrigin
import javafx.stage.Screen; //导入方法依赖的package包/类
private void setArenaScreenOrigin(Screen screen) {
final double dpiScaleFactor = ShootOFFController.getDpiScaleFactorForScreen();
final Rectangle2D arenaScreenBounds = screen.getBounds();
arenaScreenOrigin = new Point2D(arenaScreenBounds.getMinX() * dpiScaleFactor,
arenaScreenBounds.getMinY() * dpiScaleFactor);
logger.debug("Set arenaScreenOrigin to {}", arenaScreenOrigin);
}