displaying frame first

hi everybody,

i wrote an application using swing. it does some initial hard disk browsing

before the user can interact with it. this browsing may take some seconds,

so i wanted to show the frame first, then do the browsing, and after this is finished, update the gui accordingly.

so i wrote s.th like the following:

privatestaticvoid createAndShowGUI(){

MainFrame mainFrame =new MainFrame();

mainFrame.pack();

mainFrame.setVisible(true);

// browsing stuff

..........

}

publicstaticvoid main(String[] args){

javax.swing.SwingUtilities.invokeLater(new Runnable(){

publicvoid run(){

createAndShowGUI();

}

});

}

but the result is that the frame with its frame title is shown, but none of the

components within the frame... oO ?!?

how do i do this right?

thanks in advance for any comments!

well the rest of course is shown as well, but after the stuff is done. so it looks quite nasty for a few seconds...

[1659 byte] By [smallsa] at [2007-11-27 8:16:25]
# 1
Your "browsing stuff" need to execute in a separate Thread so it doesn't block the GUI from painting itself. Then if you need to update the GUI from that Thread you use the SwingUtilities.invokeLater(..) method.
camickra at 2007-7-12 20:01:19 > top of Java-index,Desktop,Core GUI APIs...
# 2
so where should i do the "browsing stuff"?and if i should then use invokeLater to do the GUI-related update, how do i get the references to the swing components that were created in the mainFrame constructor?Message was edited by: smalls
smallsa at 2007-7-12 20:01:19 > top of Java-index,Desktop,Core GUI APIs...
# 3
Maybe this posting will help with the concept of creating a separate Thread: http://forum.java.sun.com/thread.jspa?forumID=57&threadID=621226
camickra at 2007-7-12 20:01:19 > top of Java-index,Desktop,Core GUI APIs...
# 4

> now i'm wondering why the whole gui stuff (i.e. the stuff in the main

> method and in the constructor of the frame) isn't done in the

> eventDispatch thread, as it should be done according to the tutorials?

Its an example....written before the tutorials where updated to use the approach now used. Although the code is "technically" not thread safe, it is "practically" thread safe as explained in this article:

http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html#exceptions

I can't be bothered to update my 1000's of examples.

camickra at 2007-7-12 20:01:19 > top of Java-index,Desktop,Core GUI APIs...