Solved

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

Posted on 2004-10-03
6
167 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now