• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Trouble with return value from a JDialog

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic