Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-10-03
6
Medium Priority
?
181 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 375 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.
Suggested Courses

926 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