[英]Wait cursor before the Application starts Java swing
我想在應用程序開始之前將游標更改為沙漏。當您單擊Eclipse中的“運行”時,它應該顯示沙漏。 我的應用程序花了4秒鍾左右的時間來加載Swing應用程序,其中花了大約3秒鍾來獲取與系統相關的屬性。 我嘗試使用setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
。但是沒有太多改進
任何人都可以在這方面提供幫助
這是我的代碼
public static void main(String args[]){
String os = System.getProperty("os.name").trim().toLowerCase();
if (!os.equals("windows server 2008 r2") &&
!os.equals("windows server 2012")) {
JOptionPane.showMessageDialog(null, TPDI18N.formatWithBundle(
SsUtils.SS, "ss.error.notSupportedPlatform", os),
TPDI18N.getString("common.error"), JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
System.setProperty("sun.awt.exception.handler",
"somepackage");
ThreadGroup threadGroup = new ThreadGroup("My title") {
@Override
public void uncaughtException(Thread t, Throwable e) {
if (!(e instanceof ThreadDeath)) {
ErrorUtil.logErrorAndExit(e);
}
}
};
Runnable r = new Runnable() {
public void run() {
startApplication();
}
};
new Thread(threadGroup, r).start();
}
private static void startApplication() {
DirUtil.setAppDir(AppLICATION);
MyManager.startGUI(new String[0], LOG4J_SS_CONFIG);//Maximum time is consumed at this place
DirUtil.setHelpTopicDirectory(IMC_HELP_DIR);
WindowsConfigurator.makeInstance(TPDDirUtil.makeLogDir());
MyClassManager main = new MyClassManager();
main.setSize(new Dimension(1000, 720));
centerWindow(main);
main.setVisible(true);
main.setMinimumSize(main.getSize());
}
public MyClassManager() {
super(TPDI18N.getString(Utils.AA, "aa.title"));
//here creation of panel takes place
---
--
}
您的問題可能是您正在加載的代碼正在Swing事件線程上運行,從而導致無法看到光標更改。 一種解決方案是使用SwingWorker在后台線程中執行加載代碼,從而釋放Swing事件分發線程來完成其工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.