JDialog在失去焦点时冻结



我有一个程序,我正在工作,应该是通过允许您在地图中编辑单个纹理来促进纹理贴图的制作。我在几个地方使用JDialog来输入地图的平铺大小、新地图的初始大小,以及用户在使用外部程序(如photoshop或paint)编辑所选纹理时只需按下按钮的地方。但是,只要这些JDialog中的任何一个启动,如果程序失去焦点,它就会完全失去响应。这是我的代码,弹出的JDialog当你编辑选定的纹理外部:

JDialog editing = new JDialog(mainFrame, "Externally Editing");//mainFrame is the name of the JFrame containing everything.
JPanel pnl = new JPanel();
editing.setLayout(new BorderLayout());
pnl.setPreferredSize(new Dimension(150, 60));
editing.add(pnl);
editing.pack();
JButton button = new JButton("Done Editing");
button.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
        editng = false;//Obviously, a boolean that I have outside of this method.
    }
});
pnl.add(button);
Thread.sleep(100);
editing.setVisible(true);
while(editng){System.out.print("");}//Doing nothing while the user is externally editing.. Unfortunately, if I don't have "System.out.print("");" it doesn't work.. Oh, Java..
new Thread(new Runnable(){public void run(){editing.dispose();}}).start();//Gotta dispose of it in a separate thread since AWT isn't Thread-safe... Ugh..

我假设它冻结在AWT线程中,它为JDialog创建/拥有,而我的线程只是等待按钮被按下。这是不可能发生的,因为JDialog被冻结了。

设置对话框为模态。您的应用程序将停止处理,直到对话框关闭

为什么要这么假?只需在侦听器中处理对话框。

最新更新