0

The first time I show my Component, it takes a few seconds to show. I am using a card layout. When I switch to a card for the first time is when I experience the slowness. Every time after that, it is almost instant.

I have two questions about this:

For Swing components, is there a way to kick this off early, for example, during application load?

What is happening under the hood that causes the first display to take longer than all the others.

user489041
  • 27,916
  • 55
  • 135
  • 204
  • 2
    Card panels are loaded when the application is loaded an before the frame is displayed. The CardLayout needs the size of the card panels so it can determine the preferred size for the card panel. Therefore all components should already be created. I don't see why there would be a delay. Post your [SSCCE](http://sscce.org/) that demonstrates the problem. – camickr Mar 12 '15 at 04:08
  • 1
    *"is there a way to kick this off early, for example, during application load?"* Sure, you can create it on a separate `Thread` (possibly using a `SwingWorker`) after the initial GUI is created. The only delay will be in if the user wants that component early after opening the app. *"What is happening under the hood that causes the first display to take longer than all the others."* Most probably 'constructing the component(s)'. But we'll know better when you post an SSCCE as suggested by @camickr. – Andrew Thompson Mar 12 '15 at 04:50
  • 2
    For [example](http://stackoverflow.com/a/25526869/230513). – trashgod Mar 12 '15 at 07:07

0 Answers0