Problem with repainting

Hi all

I have a serious problem that I cant resolve, I will try as best to be as clear as I can be.

I have a JProgressBar, the value gets set else where and passes this value into the progress bar class, the problem I am having is two fold firstly, even though the value is been constantly set , a visible change is only seen at the end of the whole process, the second part of the problem is this, if the screen is minimized and maximized the whole screen remains orange until the process is complete, then the screen returns. The strange thing is that I am not calling a validate or repaint method after the process is done.

the second problem is seen throughout the whole program for instance I am streaming results into a JTable it used to update line by line, now the whole table only displays once the last value has been streamed in, if the screen is minimized and maximized the orange screen returns.

so to summarise anywhere in the program where a component needs to updated it isn't (even if I repaint and validate) and once a process is complete everything displays and that Damm orange.

Any thoughts out there would be appreciated

thanks in advance Brian

[1210 byte] By [Brian.R.Johnsona] at [2007-10-3 4:31:20]
# 1

You are performing time consuming tasks on the event dispatch thread (EDT).

For example, something like this...

public void actionPerformed(ActionEvent e)

{

doSomethingThatTakesQuiteAWhile();

}

...will lock up the GUI, since nothing (ie painting, events etc) can be processed until your method returns.

Google for "swing threads" and hit "I'm feeling lucky."

itchyscratchya at 2007-7-14 22:34:46 > top of Java-index,Desktop,Core GUI APIs...
# 2

Well I would agree with you in theory the problem is that for example the result set will only return 30 rows and then the value is set, then another 30 rows are returned and the progress bar set, even if i disable the work that is done on the result sets and just set the values of the Progress bar the problem persists.

Brian.R.Johnsona at 2007-7-14 22:34:46 > top of Java-index,Desktop,Core GUI APIs...
# 3
Well it's hard to make any useful guesses without seeing any pertinent code :o)
itchyscratchya at 2007-7-14 22:34:46 > top of Java-index,Desktop,Core GUI APIs...
# 4
that is fair, so is there any code that i could provide to you that would perhaps make it a bit easier for you to make a diagnosis
Brian.R.Johnsona at 2007-7-14 22:34:46 > top of Java-index,Desktop,Core GUI APIs...
# 5
The bit with the bug in it :o)It's kind of hard to say what I need to look at without knowing what there is to look at. The bits that are running the time-consuming processes, the bits that aren't working, the bits that update the progress bar. Try something.
itchyscratchya at 2007-7-14 22:34:46 > top of Java-index,Desktop,Core GUI APIs...
# 6

> Well I would agree with you in theory the problem is

> that for example the result set will only return 30

> rows and then the value is set, then another 30 rows

> are returned and the progress bar set, even if i

> disable the work that is done on the result sets and

> just set the values of the Progress bar the problem

> persists.

That's not the point. The point is that you can set the progress position all you like and nothing will happen until you release the dispatcher thread to allow it to refresh what you are seeing.

When you make a change like this all the repainting is added to the dispactcher's TODO list. But if the dispatcher is still running an [b]actionPerformed[/b] method then it's not looking at that list.

You need to create a seperate Thread, usually called a "worker" thread to do you database work. Don't do anything in an actionPerformed method which takes more than a fraction of a second.

Typically the actionPerformed method will just disable the control, then create and start a thread to do the work, then exit (the thread re-enables the control when it's done).

Something like;

[code]

private Action launchSQL = new AbstractAction("Go") {

public void actionPerformed(ActionEvent e) {

setEnabled(false);

Thread worker = new Thread(new Runnable() {

public void run() {

try {

doSQLStuff();

}

finally {

setEnabled(true);

}

}}, "SQL Worker thread");

worker.start();

}

};

[code]

malcolmmca at 2007-7-14 22:34:46 > top of Java-index,Desktop,Core GUI APIs...
# 7
thaks for your help guys it works like a dream
Brian.R.Johnsona at 2007-7-14 22:34:46 > top of Java-index,Desktop,Core GUI APIs...