Solved

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

Posted on 2004-10-03
6
168 Views
Last Modified: 2010-03-31
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?

0
Comment
Question by:anthony0007
6 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12214007
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.
0
 
LVL 2

Expert Comment

by:Breadstick
ID: 12214049
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();
0
 
LVL 2

Expert Comment

by:Breadstick
ID: 12214053
Whoops, that was incorrect.  Use this:

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

Author Comment

by:anthony0007
ID: 12214143
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
0
 
LVL 3

Accepted Solution

by:
CI-Ia0s earned 125 total points
ID: 12214247
I don't think so. P.S. I've had problems with using
new Thread()
{
     public void run()
     {
          // ... put your code that retrieves the data in here.
     }
}.start();

If that doesn't work for you, try:

Thread processingThreead = new Thread(new Runnable()
{
     public void run()
     {
          // ... put your code that retrieves the data in here.
     }
});
processingThread.start();
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question