Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Java警报集中在JavaFX节点上[例如StackPane或按钮]_Java_Javafx_Alert - Fatal编程技术网

将Java警报集中在JavaFX节点上[例如StackPane或按钮]

将Java警报集中在JavaFX节点上[例如StackPane或按钮],java,javafx,alert,Java,Javafx,Alert,浏览网页,我没有找到任何解决办法。下图说明了我想要实现的目标: 一个可能的解决方案是为一个屏幕的计算机创建的,对于多个屏幕,它需要修改。虽然它可以[在一个屏幕上]工作,但我不确定这是否是正确的方法 问题: 这是正确的方向吗?JavaFX可能没有为节点构建这样的功能,而它只为Stage构建了这样的功能 代码: 以及上面缺少的两种方法: /** * Gets the visual screen width. * * @return The screen <b>

浏览网页,我没有找到任何解决办法。下图说明了我想要实现的目标:

一个可能的解决方案是为一个屏幕的计算机创建的,对于多个屏幕,它需要修改。虽然它可以[在一个屏幕上]工作,但我不确定这是否是正确的方法

问题: 这是正确的方向吗?JavaFX可能没有为节点构建这样的功能,而它只为Stage构建了这样的功能

代码:

以及上面缺少的两种方法:

/**
     * Gets the visual screen width.
     *
     * @return The screen <b>Width</b> based on the <b>visual bounds</b> of the
     *         Screen.These bounds account for objects in the native windowing
     *         system such as task bars and menu bars. These bounds are
     *         contained by Screen.bounds.
     */
    public static double getVisualScreenWidth() {
    return Screen.getPrimary().getVisualBounds().getWidth();
    }

    /**
     * Gets the visual screen height.
     *
     * @return The screen <b>Height</b> based on the <b>visual bounds</b> of the
     *         Screen.These bounds account for objects in the native windowing
     *         system such as task bars and menu bars. These bounds are
     *         contained by Screen.bounds.
     */
    public static double getVisualScreenHeight() {
    return Screen.getPrimary().getVisualBounds().getHeight();
    }

请看一下


此实现将警报集中在当前屏幕中,如果需要实现不同的集中逻辑,可以编辑方法centerAlertInStage

尝试使其也适用于一般节点,而不仅仅是阶段+感谢您的尝试。感谢@GOXR3PLUS,现在它可以在给定节点的情况下工作。还修复了显示对话框时闪烁的问题。我将尝试:
/**
     * Gets the visual screen width.
     *
     * @return The screen <b>Width</b> based on the <b>visual bounds</b> of the
     *         Screen.These bounds account for objects in the native windowing
     *         system such as task bars and menu bars. These bounds are
     *         contained by Screen.bounds.
     */
    public static double getVisualScreenWidth() {
    return Screen.getPrimary().getVisualBounds().getWidth();
    }

    /**
     * Gets the visual screen height.
     *
     * @return The screen <b>Height</b> based on the <b>visual bounds</b> of the
     *         Screen.These bounds account for objects in the native windowing
     *         system such as task bars and menu bars. These bounds are
     *         contained by Screen.bounds.
     */
    public static double getVisualScreenHeight() {
    return Screen.getPrimary().getVisualBounds().getHeight();
    }