我正在 NetBeans 框架(RCP)上开发一个 Java 应用程序。当应用程序运行并可见时,我想显示一个“请稍候”对话框,该对话框将禁止用户使用 GUI,直到正在运行的线程完成。请看下面我的代码。它现在的工作方式是在应用程序可见之前显示“请稍候”对话框。再一次,我想在应用程序可见时显示“请稍候”对话框,而不是之前。我该怎么做呢?
public final class MyTopComponent extends TopComponent {
public CoreTopComponent() {
initComponents();
}
@Override
public void componentOpened() {
//Show a Dialog ontop of the application with a Please Wait message so that the user cannot use the application until the following threads
//are complete. The Dialog is supposed to automatically close once the threads are complete.
JOptionPane.showOptionDialog(this, "Please Wait...",
"Please Wait...", JOptionPane.PLAIN_MESSAGE,
JOptionPane.PLAIN_MESSAGE, null, new Object[] {},
null);
//There are 10 threads like the following 2 that perform something and in the end update the GUI
final Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
//Step 1 - Create class that initializes configuration
//Step 2 - Create class that performs something using configuration
//Step 3 - Update GUI on the EDT using SwingUtilities.invokeLater
}
});
t1.start();
final Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
//Step 1 - Create class that initializes configuration
//Step 2 - Create class that performs something using configuration
//Step 3 - Update GUI on the EDT using SwingUtilities.invokeLater
}
});
t2.start();
}
@Override
public void componentClosed() {
}
void writeProperties(java.util.Properties p) {
// better to version settings since initial version as advocated at
// http://wiki.apidesign.org/wiki/PropertyFiles
p.setProperty("version", "1.0");
// TODO store your settings
}
void readProperties(java.util.Properties p) {
String version = p.getProperty("version");
// TODO read your settings according to their version
}
}
我尝试使用以下内容,但仍然发生相同的情况:
@Override
public void componentShowing() {
JOptionPane.showOptionDialog(this, "Please Wait...",
"Please Wait...", JOptionPane.PLAIN_MESSAGE,
JOptionPane.PLAIN_MESSAGE, null, new Object[]{},
null);
}