1

我想将我的程序更新到 Java 7,但是当我运行它时,它仍然被阻止。我创建了一个 UI SwingUtilities.invokeAndWait

 SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            createUI(MyManagerClass.getInstance());
        }
    });

但是,run从不调用。我不明白为什么,因为使用 Java 6 它可以工作,如果我查看线程我找不到死锁。

所有代码:

public class MainGUI extends SingleFrameApplication {
    protected void startup() {
        final JPanel panel = new JPanel();
        MyManagerClass.getInstance().setMainPanel(panel);
        show(panel);
        Worker.post(new Job() {
            @Override
            public Object run() {
                initUI();
                return null;
            }
        });
        getMainView().getFrame().pack();
        getMainView().getFrame().setResizable(false);

        panel.repaint();
    }
    private void initUI(){
        MyUIClass.init(MyManagerClass.getInstance());
    }
}

public class MyUIClass {
    public static void init(MyManagerClass class){
        JPanel panel = class.getMainPanel();
        panel.add(getComponent());
    }

    protected JComponent getComponent() {
        if (panel == null) {
            panel = new JPanel();
            fillPanel();
        }
        return panel;
    }

    protected void fillPanel() {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    createUI(MyManagerClass.getInstance());
                }
            });
        } catch (InterruptedException e) {
            log.error(e, e);
        } catch (InvocationTargetException e) {
            log.error(e, e);
        }
   }
}
4

0 回答 0