我想将我的程序更新到Java 7,但是当我运行它时,它仍然被阻止。我使用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);
}
}
}