如果在Mac OS上完全屏蔽,JavaFX警报#showAndWait将永久挂起

如果在Mac OS上完全屏蔽,JavaFX警报#showAndWait将永久挂起,java,swing,javafx,freeze,Java,Swing,Javafx,Freeze,(tl;接近底部的dr标记) 上下文 我在一个典型的全屏(POS风格)JFX应用程序中使用JavaFX警报来显示swing内容窗格,以便在阻止窗口中用定制的触摸优化输入提示用户。 我希望警报是全屏的,以符合pos风格。在Mac电脑上,全屏窗口在自己的“空间”中打开;类似于新的桌面空间,但仅适用于一个应用程序 我使用的是运行MacOS10.12的黑客软件。这个问题似乎与Macintosh全屏空间非常相关 值得注意的是,复制需要系统首选项>停靠>首选选项卡…=手册这导致Mac OS将警报作为单独的弹

(tl;接近底部的dr标记)

上下文 我在一个典型的全屏(POS风格)JFX应用程序中使用JavaFX警报来显示swing内容窗格,以便在阻止窗口中用定制的触摸优化输入提示用户。

我希望警报是全屏的,以符合pos风格。在Mac电脑上,全屏窗口在自己的“空间”中打开;类似于新的桌面空间,但仅适用于一个应用程序

我使用的是运行MacOS10.12的黑客软件。这个问题似乎与Macintosh全屏空间非常相关

值得注意的是,复制需要系统首选项>停靠>首选选项卡…=手册这导致Mac OS将警报作为单独的弹出窗口打开,而不是作为同一应用程序阶段窗口中的选项卡打开。(或者你可以拖出标签页,手动全屏显示,请随意。)我这样做是因为在标签页中呈现swing内容时,警报效果不佳

主场景窗口的全屏状态不影响行为,只影响警报状态

SDK:JDK13.0.4、JavaFX11.0.2

showAndWait() 正在使用
Alert.showAndWait()
显示警报,其中

显示对话框并等待用户响应(换句话说,是 打开一个阻塞对话框,返回用户输入的值)。
。。。
方法必须在JavaFX应用程序线程上调用
。。。
必须被称为。。。从传递给的Runnable的run方法 Platform.runLater

正如您在下面看到的,最后一个要求得到了满足。我还检查了以确保它在JFX应用程序线程上被调用

预期 show和wait();挂起,直到用户单击警报窗口上的“确定”。之后,窗口关闭,自定义对话框返回从用户收集的值。焦点将返回到JFX应用程序阶段窗口

实际的 实际实现:
如果是窗口,则返回并按预期关闭,焦点返回到包含应用程序场景窗口的空间。如果全屏显示,Mac全屏空间立即消失,没有动画,返回桌面,似乎表明警报窗口突然不再存在,就好像它已经关闭一样,但内容仍然呈现在桌面空间的所有其他内容上。应用程序线程挂起。UI挂起。老鼠沙滩球

简化测试版本:
如果窗口按预期关闭。如果全屏显示,则返回到窗口,停止渲染但保持打开状态。应用程序线程没有停止,但应用程序仍然没有响应(不是“没有响应”,是在海滩上打球,是停止了,只是对任何交互一无所知。)

闲逛 ,我无法复制,但它只是进一步表明这与玻璃窗有关,导致我猜测这是quantum工具包的问题,或者Mac玻璃窗在试图关闭时在空间之间移动(并重新渲染?)

太长了,读不下去了 不知何故,警报关闭导致的全屏空间切换会中断警报的用户确认事件,该事件将释放线程,导致应用程序线程永远停留在showAndWait()中。我认为整个程序在确认后挂起的原因与警报UI不再可用有关;JavaFX现在正试图将控制权返回到挂起的应用程序线程

可以理解的是,警报窗口可能没有以这种方式进行测试;一个全屏弹出式输入窗口,包含所有Mac的全屏空间

我可能只需要研究另一个选项,或者不用全屏就足够了

强制代码转储 对话类:

package swing;

import javafx.application.Platform;
import javafx.embed.swing.SwingNode;
import javafx.scene.control.Alert;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * Absofuckinlutely not done.
 *
 * TODO P1: DIALOG DOES NOT RETURN WHEN USER CLICKS OK WHILST IN FULLSCREEN!
 * TODO There's literally 0 javadoc. oh well!
 * @author Gordie
 * @version -
 * @since -
 */
public class numericInput extends Alert {

    private static int value;
    //#region swing
    private JTextField outputField;
    private JButton btn1;
    private JButton btn2;
    private JButton btn3;
    private JButton btn4;
    private JButton btn5;
    private JButton btn6;
    private JButton btn7;
    private JButton btn8;
    private JButton btn9;
    private JButton btnCancle;
    private JButton btn0;
    private JButton btnEnter;
    private JPanel panel;
    //#endregion swing

    public numericInput(String text) {
        super(AlertType.INFORMATION, text);
        addListener(btn0, 0);
        addListener(btn1, 1);
        addListener(btn2, 2);
        addListener(btn3, 3);
        addListener(btn4, 4);
        addListener(btn5, 5);
        addListener(btn6, 6);
        addListener(btn7, 7);
        addListener(btn8, 8);
        addListener(btn9, 9);

        btnCancle.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                panel.setVisible(false);
                value = -1;
            }
        });

        btnEnter.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                panel.setVisible(false);
            }
        });


        //#region REDACTED
        /*
            Displaying a Swing JDialog for a JavaFX  application was too much of a
            pain in the arse that wasn't really working out for us.
            Instead of re-creating the entire dialog in JFX,
            i'm just displaying the swing panel in a JFX stage as a node using jfx.embed
         */

        //panel.setVisible(true);
        //getContentPane().add(panel);
        //pack();
        //setTitle(title);
        //setVisible(true);
        //#endregion

        // Show
        setResizable(true);
        SwingNode sNode = new SwingNode();                                                                              // Create JFX compatible node to contain Swing content,
        sNode.setContent(panel);                                                                                        // and add dialog pane to it.
        getDialogPane().setContent(sNode);                                                                              // Add the content node to the pane of the JFX dialog window this class extends.
        getDialogPane().autosize();
        Platform.runLater(() -> {
            showAndWait();
            close();
        });
    }

    //#region listener
    private void append(int s){
        outputField.setText(outputField.getText() + s);
    }

    private void addListener(JButton button, int number){
        button.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                append(number);
            }
        });
    }
    //#endregion

    public static numericInput New(String text){
        return new numericInput(text);
    }

    public int value(){
        return value;
    }
}

剥离测试应用:
(与实际实现不完全相同)

提示形式:

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="swing.numericInput">
  <grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="5" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
    <margin top="0" left="0" bottom="0" right="0"/>
    <constraints>
      <xy x="20" y="20" width="500" height="400"/>
    </constraints>
    <properties/>
    <border type="none"/>
    <children>
      <component id="e6243" class="javax.swing.JTextField" binding="outputField">
        <constraints>
          <grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
            <preferred-size width="150" height="-1"/>
          </grid>
        </constraints>
        <properties>
          <editable value="false"/>
        </properties>
      </component>
      <component id="6d99d" class="javax.swing.JButton" binding="btn1">
        <constraints>
          <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="1"/>
        </properties>
      </component>
      <component id="68db2" class="javax.swing.JButton" binding="btn4">
        <constraints>
          <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="4"/>
        </properties>
      </component>
      <component id="7f847" class="javax.swing.JButton" binding="btn7">
        <constraints>
          <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="7"/>
        </properties>
      </component>
      <component id="bbd8" class="javax.swing.JButton" binding="btn2">
        <constraints>
          <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="2"/>
        </properties>
      </component>
      <component id="4ab8f" class="javax.swing.JButton" binding="btn5">
        <constraints>
          <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="5"/>
        </properties>
      </component>
      <component id="ce17e" class="javax.swing.JButton" binding="btn8">
        <constraints>
          <grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="8"/>
        </properties>
      </component>
      <component id="890ed" class="javax.swing.JButton" binding="btn3">
        <constraints>
          <grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="3"/>
        </properties>
      </component>
      <component id="f1bdb" class="javax.swing.JButton" binding="btn6">
        <constraints>
          <grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="6"/>
        </properties>
      </component>
      <component id="beed0" class="javax.swing.JButton" binding="btn9">
        <constraints>
          <grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="9"/>
        </properties>
      </component>
      <component id="60bed" class="javax.swing.JButton" binding="btn0">
        <constraints>
          <grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="0"/>
        </properties>
      </component>
      <component id="2d5d5" class="javax.swing.JButton" binding="btnCancle">
        <constraints>
          <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="Delete"/>
        </properties>
      </component>
      <component id="960c7" class="javax.swing.JButton" binding="btnEnter">
        <constraints>
          <grid row="4" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="Enter"/>
        </properties>
      </component>
    </children>
  </grid>
</form>


<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="swing.numericInput">
  <grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="5" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
    <margin top="0" left="0" bottom="0" right="0"/>
    <constraints>
      <xy x="20" y="20" width="500" height="400"/>
    </constraints>
    <properties/>
    <border type="none"/>
    <children>
      <component id="e6243" class="javax.swing.JTextField" binding="outputField">
        <constraints>
          <grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
            <preferred-size width="150" height="-1"/>
          </grid>
        </constraints>
        <properties>
          <editable value="false"/>
        </properties>
      </component>
      <component id="6d99d" class="javax.swing.JButton" binding="btn1">
        <constraints>
          <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="1"/>
        </properties>
      </component>
      <component id="68db2" class="javax.swing.JButton" binding="btn4">
        <constraints>
          <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="4"/>
        </properties>
      </component>
      <component id="7f847" class="javax.swing.JButton" binding="btn7">
        <constraints>
          <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="7"/>
        </properties>
      </component>
      <component id="bbd8" class="javax.swing.JButton" binding="btn2">
        <constraints>
          <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="2"/>
        </properties>
      </component>
      <component id="4ab8f" class="javax.swing.JButton" binding="btn5">
        <constraints>
          <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="5"/>
        </properties>
      </component>
      <component id="ce17e" class="javax.swing.JButton" binding="btn8">
        <constraints>
          <grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="8"/>
        </properties>
      </component>
      <component id="890ed" class="javax.swing.JButton" binding="btn3">
        <constraints>
          <grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="3"/>
        </properties>
      </component>
      <component id="f1bdb" class="javax.swing.JButton" binding="btn6">
        <constraints>
          <grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="6"/>
        </properties>
      </component>
      <component id="beed0" class="javax.swing.JButton" binding="btn9">
        <constraints>
          <grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="9"/>
        </properties>
      </component>
      <component id="60bed" class="javax.swing.JButton" binding="btn0">
        <constraints>
          <grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="0"/>
        </properties>
      </component>
      <component id="2d5d5" class="javax.swing.JButton" binding="btnCancle">
        <constraints>
          <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="Delete"/>
        </properties>
      </component>
      <component id="960c7" class="javax.swing.JButton" binding="btnEnter">
        <constraints>
          <grid row="4" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
        </constraints>
        <properties>
          <text value="Enter"/>
        </properties>
      </component>
    </children>
  </grid>
</form>