-1

I tried searching for documentation on this and found virtually nothing. I must be looking in the wrong place. I have a button used to open another JFrame object. From what I've seen, most folks recommend opening the JFrame using the statement: myFrame.setVisible(true);

When this JFrame opens, there are several SQL statements run which retrieve the data required to make the JFrame usable. I would like to ensure all the data is retrieved and loaded into the JFrame's controls before the JFrame becomes visible to the user. So I thought it would help to know the event sequence, you know, which event is fired first, second, third... So that I can find an event in the chain which enables me to keep the JFrame hidden until everything is ready for user interaction. Thanks for taking the time to reply.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Pete Hahn
  • 21
  • 6

1 Answers1

1

Because of the unknown latency in accessing your database, you'll likely want to read the required data in the background to avoid blocking the event dispatch thread. SwingWorker is a common approach. In this way, you can invoke the frame's setVisible(true) method promptly, disabling any controls that don't make sense while the data loads. Results can be displayed as they become available and progress shown, resulting in reduced perceived latency. Later, in your implementation of done() you can enable the disabled controls. A related example is shown here, and a variation is shown here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Thanks trashgod, I had not considered simply disabling the controls until everything is ready for use. Still, it would be ideal in my mind not to present this form until it is fit and ready for use. If no one present that solution I will opt for the SW and enable controls with a property change listener once the SW completes. – Pete Hahn Jun 04 '15 at 01:08