swing 创建一个“请稍候...”弹出窗口
示例
可以将此代码添加到任何事件,例如侦听器,按钮等。JDialog将出现阻塞,并将一直保留到该过程完成为止。
final JDialog loading = new JDialog(parentComponent);
JPanel p1 = new JPanel(new BorderLayout());
p1.add(new JLabel("请耐心等待..."), BorderLayout.CENTER);
loading.setUndecorated(true);
loading.getContentPane().add(p1);
loading.pack();
loading.setLocationRelativeTo(parentComponent);
loading.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
loading.setModal(true);
SwingWorker<String, Void> worker = new SwingWorker<String, Void>() {
@Override
protected String doInBackground() throws InterruptedException
/** Execute some operation */
}
@Override
protected void done() {
loading.dispose();
}
};
worker.execute(); //在这里进程线程启动
loading.setVisible(true);
try {
worker.get(); //此处父线程等待完成
} catch (Exception e1) {
e1.printStackTrace();
}
热门推荐
8 怎么说祝福语简短
10 早晨好正能量祝福语简短
11 中秋妈妈生日祝福语简短
12 端午发给客户祝福语简短
13 祝福语怎么写大全简短
14 给侄子祝福语简短精辟
15 给老师祝福语简短创意
16 生日祝福语 简短独特老弟
17 顾客简短祝福语大全集
18 祖国生日祝福语简短英文