user2629457
user2629457

Reputation: 13

Wait cursor before the Application starts Java swing

I want to change the Cursor to hour glass before the Appliation starts As you click the "run " in eclipse it should show the Hour glass. My application takes arount 4secs to load the Swing Application in which around 3secs are taken for getting the system related properties. I tried using setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));.but there is not much improvments

Can anyone help in this regard

This is my code

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
    ---
    --
    }

Upvotes: 0

Views: 260

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285405

Likely your problem is that you're loading code is running on the Swing event thread, preventing your cursor changes from being seen. A solution is to use a SwingWorker to do the loading code in a background thread, freeing up the Swing event dispatch thread to do its work.

Upvotes: 3

Related Questions