本文整理汇总了Java中javafx.stage.Window.getX方法的典型用法代码示例。如果您正苦于以下问题:Java Window.getX方法的具体用法?Java Window.getX怎么用?Java Window.getX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.stage.Window
的用法示例。
在下文中一共展示了Window.getX方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例2: press
import javafx.stage.Window; //导入方法依赖的package包/类
@Override
public void press(MouseEvent e) {
Window window = get();
if (isEnable() && e.isConsumed() == false && window != null) {
if (canDrag(new Point2D(e.getSceneX(), e.getSceneY()), window.getX() + window.getWidth(), window.getY() + window.getHeight())) {
startX = e.getScreenX() - window.getX();
startY = e.getScreenY() - window.getY();
e.consume();
pressed = true;
}
}
}
示例3: showTooltip
import javafx.stage.Window; //导入方法依赖的package包/类
private void showTooltip() {
if (!comboBox.getTooltip().isShowing()) {
Window stage = comboBox.getScene().getWindow();
double posX = stage.getX() +
comboBox.localToScene(comboBox.getBoundsInLocal()).getMinX() + 4;
double posY = stage.getY() +
comboBox.localToScene(comboBox.getBoundsInLocal()).getMinY() - 29;
comboBox.getTooltip().show(stage, posX, posY);
}
}