【发布时间】:2013-06-02 22:03:13
【问题描述】:
我正在开发一个程序,该程序旨在通过允许您编辑贴图中的单个纹理来促进纹理贴图的制作。我有几个地方使用 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..
我会假设它在它为 JDialog 创建/拥有的 AWT 线程中冻结,而我的线程只是在等待按钮被按下。这不可能发生,因为 JDialog 被冻结了。
【问题讨论】:
-
使您的对话模式化。您的应用程序将停止处理,直到对话框关闭。
-
哦。谢谢!大声笑.. 把它作为一个答案,我会接受它。
标签: java swing user-interface jdialog