my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes Trouble with return value from a JDialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Trouble with return value from a JDialog" Watch "Trouble with return value from a JDialog" New topic
Author

Trouble with return value from a JDialog

Jason Guyton
Ranch Hand

Joined: Apr 15, 2010
Posts: 40
I thought I had this one working, but seems I've honked it up.

I'm trying to popup a window that displays the list of available players. The user clicks a name on the list, some text fields on the right fill in with the selected plyaer's info. This all works fine. The getSelectedIndex method works fine for those text fields. But I can't seem to return that index when the user clicks the Select button. Seems like it's something really simple I'm overlooking.



Also, it seems like the PlayerPicker method returns a value to the parent before the input is given. It pops the window up, but then it doesn't wait for the return from initGUI. I thought setting modal to true would fix that.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Seems like it's something really simple I'm overlooking.

initGUI() returns immediately (there's no setVisible(..) in the code), so
int indx = initGUI();
is determined prior to any selection
Jason Guyton
Ranch Hand

Joined: Apr 15, 2010
Posts: 40
OK, I stuck this.setVisible(true) in at the bottom, right above the return statement of initGUI. It returns the proper value now. But, when I click the select button, the window doesn't go away. If I hit it again, it disappears and does what I want. In fact, I can select a different player from the list before the second click on Select and it still returns the original value. Odd behavior for a button that has dispose() as it's only function.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
sounds like in the code you're not showing you have another setVisible(true) (perhaps the original)
that simply re-shows the dialog after it is initially disposed (very quickly, and you wouldn't notice it)

Jason Guyton
Ranch Hand

Joined: Apr 15, 2010
Posts: 40
Michael Dunn wrote:sounds like in the code you're not showing you have another setVisible(true) (perhaps the original)
that simply re-shows the dialog after it is initially disposed (very quickly, and you wouldn't notice it)


You are good. I had a setVisible in the parent class, not sure why I did that. All is good now. Thank you very much. Now my last hurdle is the JTable. But, I'm gonna try to code it up from scratch and see what happens.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble with return value from a JDialog