开发者

Swing invokelater freeze

开发者 https://www.devze.com 2023-04-04 21:05 出处:网络
im calling invokeLater direcly from button on actionPerformed with this code: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

im calling invokeLater direcly from button on actionPerformed with this code:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
   SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            int temp = (jComboBox1.getSelectedIndex() + 1);
        heavyPro开发者_JAVA百科ccesingFunction();
        }
   });
} 

and that still freezes the GUI. Why? I get the same result without using the invokelater function.

should I Use

Thread queryThread = new Thread() {
      public void run() { 

instead?

Edit:

Thanks, new thread should be used.


invokeLater still ends up running the code on the dispatcher thread - just later. The aim of invokeLater is to allow background threads to post work on the event dispatcher thread.

It sounds like you should indeed create another thread - or use a thread pool for the same sort of effect, or SwingWorker for example. Whatever you do, you need to avoid running your slow method on the event dispatcher thread.

0

精彩评论

暂无评论...
验证码 换一张
取 消