Link to home
Start Free TrialLog in
Avatar of anthony0007
anthony0007

asked on

Displaying a status window while data is being retrieved from database - problem with refresh

I have a JBuilder application. It consists of an application object (inherited from Object), a Frame (using JDesktopPane) and internal frames. I retrieve a lot of data from a database. Before I start to retrieve, I open a JFrame object that I call Status_Frame. Status_Frame contains only one object, a JTextArea control. It also contains a function setText(). SetText() sets the status on both the Status_Frame's title bar as well as the JTextArea. Application object has a function named setStatus(). I have given the application object a reference to a Status_Frame. In the setStatus() function I check to see if the status window (Status_Frame) is null. If it is, I then open a new Status_Frame object. Finally, I call the setText on Status_Frame to display the status.

Although the StatusFrame is opened, the color of its background is the same as my main application Frame window - until the data retrieval finishes. Also, there doesn't seem to be any text being displayed until after all the data retrieval is done. However, the title bar changes perfectly.

Any ideas on how I get around this problem of the window not repainting?

Avatar of Mick Barry
Mick Barry
Flag of Australia image

you need to do your data retrieval in a seperate thread.
Swing is single threaded, so by doing your processing on that thread you are blocking any gui processing.
Avatar of Breadstick
Breadstick

objects is correct.  To fix your problem, put the code that retrieves the data from the database inside this:

new Thread()
{
     // ... put your code that retrieves the data in here.
}.start();
Whoops, that was incorrect.  Use this:

new Thread()
{
     public void run()
     {
          // ... put your code that retrieves the data in here.
     }
}.start();
Avatar of anthony0007

ASKER

I will give it a try, it will take a while for me to re-write my code to support this.

Why does the title bar change properly? If I use a Frame instead of a JFrame will this fix my problem?

Anthony
ASKER CERTIFIED SOLUTION
Avatar of CI-Ia0s
CI-Ia0s

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial