It's hard to answer this because it's not clear what the effects (Swing-wise) are of the calls to
new AddInventoryScreen();
andnew showStock();
. You should only touch the UI that the user sees right at the end (when all the processing is done).You should really spin off methods that will take a long time into their own Thread (see SwingWorker. There are alternatives for Java 5.0). That way, the UI won't be blocked while it's processing.
Maybe what you want is a Splash Screen?
+3
A:
Catchwa
2010-05-24 06:20:34
+1
A:
Try calling validate();
and pack();
methods before calling f.setVisible(true);
Your code can be
validate();
pack();
f.setVisible(false);
RaviG
2010-05-24 06:20:34
+1
A:
I think one big problem in your code (maybe not the only one however) is the fact that you should use a different thread for long operations.
GUI operations (creating swing components, adding them to panels, changing labels...) are to be performed exclusively in the "EDT" and must be short (typically, less than 100ms or even 50ms).
Long operations can be easily done by another thread if you use the SwingWorker API (part of JDK 1.6).
jfpoilpret
2010-05-24 06:29:02