簡體   English   中英

JDialog凍結失去焦點了嗎?

[英]JDialog Freezes on Loss of Focus?

我有一個正在使用的程序,通過允許您編輯貼圖中的單個紋理,可以簡化紋理貼圖的制作。 我在多個地方使用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被凍結了。

使對話框成為模態。 您的應用程序將停止處理,直到關閉對話框

為什么這個假的回旋處? 只需將對話框放在偵聽器中即可。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM