Blocking prevents JFrame from being fully drawn.
I have a problem that I need help with. I initially thought it was a thread problem, but now I believe it is a Swing problem. I am writing an 'int chooser'. The goal was to have it behave like a file chooser - a small JFrame opens and presents OK and CANCEL buttons, as well as a JSlider with feedback (JTextfield).
Here are the methods of interest:
I want the client call to look something like:
- Constructor - sets member variables
- showChooserFrame - does all the swing GUI creation and sets the frame visible
- run (this is a thread) - calls showChooserFrame using invokeLater. I have tried calling this from the contructor, as well as the client creating the object.
- getValue - returns the value selected by the user
- exitWindow - dispose of frame and cleanup
IntChooser ic = new IntChooser(<parameters>);
int theInt = ic.getValue();
Therefore, I need blocking somewhere while the user selects a value. Therein lies my problem. I have tried to block using many methods in several places, and every time I do, the JFrame is not completely created - it is merely a frame with a title and nothing inside. As soon as I remove blocking, the frame paints just fine, but the value is returned well before a user has a chance to do anything.
I have tried blocking at the end of the run method using a (binary) semaphore as well as a while(!userDone) loop. I have tried blocking at the beginning of the getValue method using a synchronized lock. I changed the getValue to a 'callable'. None have worked.
My exitWindow routine is called when any button is pressed or the window is closed (by the X). This is where I typically have unblocked (released semaphore, set userDone to true, etc). But that is moot really, since the frame is never fully revealed.
Any help is appreciated.