我有一个需要几秒钟才能完成的 java 例程。我想加载一个GlassPane
(可能带有“预先等待”消息),以防止用户在该例程正在执行时修改 UI,并且在例程完成时自动隐藏。为此,我使用以下代码:
Thread t = new Thread(new Runnable(){
@Override
public void run() {
/*
* `getPresentation().getFrame()` are methods that return the
* Frame which contains my UI
*/
getPresentation().getFrame().setGlassPane(myGlassPane);
getPresentation().getFrame().getGlassPane().setVisible(true);
}
});
t.start();
//this is the routine that takes several seconds to be executed
runCEM();
//hide the GlassPane
getPresentation().getFrame().getGlassPane().setVisible(false);
我设置了一个特定java.awt.Cursor
的myGlassPane
. 当我运行上面的代码时,我可以看到新的java.awt.Cursor
出现,但不是整个出现GlassPane
“请稍候”消息等等......
关于可能导致此问题的任何想法?是否有其他更好的方法来获得我正在寻找的东西而不是使用GlassPane
and Thread
?