本文整理汇总了Java中javafx.stage.Window.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Java Window.getWidth方法的具体用法?Java Window.getWidth怎么用?Java Window.getWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.stage.Window
的用法示例。
在下文中一共展示了Window.getWidth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: centerDialogOnScreen
import javafx.stage.Window; //导入方法依赖的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());
}