This is for rocking professionals. I spent a lot of time on this problem, so I’ll need a few lines to explain the problem.
I have a separate java swing application (java 6). In my application, I have a frame with a group of radio buttons. I have one action associated with all the buttons in the group. The action checks which radio button is selected and does any work. "Work" includes some background calculations, as well as some picture in two other frames in my application. Background computing is multithreaded.
I want to display a progress bar when the user selects one of the radio buttons. However, when a radio button is selected while an action on the radio button occurs, a progress indicator never appears. I tried jdialog progress indicators, glass panel, etc. None of them appear until the "work" is completed. It looks like Swing does not finish drawing the radio button until the “work” in the corresponding action is completed. And since the EDT does only one thing at a time, the progress bar dialog (or glass) is never displayed.
Then I tried to use SwingWorker to do all this “work”. Start the progress bar (or activate the glass panel), launch SwingWorker and close the progress bar (or deactivate the glass panel) in the done () method for SwingWorker. This seems to perfectly reflect the progress, but the picture, which is part of the “work”, sometimes does not finish, leaving me with some artifacts of painting (the paintComponent method is quite complicated, so I don’t want to reproduce it here). Artifacts disappear if I resize the window. This actually happens if I use a class that extends Thread instead of SwingWorker. This is all because Swing is not thread safe, and I'm trying to make the GUI work from a thread other than EDT. I understand this part.
What should I do? "work" takes about 30 seconds, and it seems too long to not show the user any indication that the program is working. I also tried changing the cursor to a wait cursor and ran into the same problems as above. The only thing I can do is turn off the frame and set the frame title to some text, for example, "working ..."
Has anyone seen this problem before?
java radio-button swingworker progressdialog
Anu
source share