It's not a secret anymore!
The moose likes Threads and Synchronization and the fly likes working with swing Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "working with swing Threads" Watch "working with swing Threads" New topic

working with swing Threads

Mohamed Iqzas
Ranch Hand

Joined: Jan 02, 2012
Posts: 72

I have a swing application. from a Jbutton actionListener i'm creating a JDialog for user inputs. Now I want the button's action Listener to proceed only after getting inputs from the user.

Please help me how to do this? I tried calling wait on thread of first actionListener, but it seems both the action listeners are in same thread, so blocking the first one blocks the other also.

Please refer the below code: (I'm not sure whether it qualifies as an SSCCE )

Chris Hurst
Ranch Hand

Joined: Oct 26, 2003
Posts: 443

Your right the two threads your code is trying to communicate with are both the one and only EDT thread ...

Either try a modal dialog so you don't need the communication (wait/notify), in which case post this on the swing forum.

Or why not do whatever you where going to do on the button actionlistener in your popup dialog.

If you really want to solve this with threads you need to get your wait off the EDT so create a new thread which waits on the dialog on the EDT and then presumably will have to SwingUtilities.invokeLater back onto the EDT when finished ;-)

"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
I agree. Here's the link:
subject: working with swing Threads
It's not a secret anymore!