Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

808 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