• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom Dialog box

 
Dan Greer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The program that I am working on pulls data from a SQL table following a search. If the search returns more than one result, I want to provide some sort of dialog window in which all of the results will be listed and double-clicking on one of them will select that result and close the dialog box, returning that value to the main window. This window needs to be able to possibly list hundreds of results. Furthermore, I would like it to be able to be like a JOptionPane which wantsInput.

I am having difficulty figuring out how to do this. I have tried extending the JOptionPane class or just using a JOptionPane to do this. My problem is that when I extend the class, I cannot figure out how to make a static method which returns a value when the window closes. When I use a a plain JOptionPane, it basically works in selecting the result that I want and returning it, however, it returns the selected string, not an index to where that string was in the array which I provided to the window. As a result, if I cannot get the index, I then have to search through that array to find the result that was being referred to instead of directly getting the index.

Can anyone provide some insight into how this may be accomplished?
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not 100% sure what you're trying to do, but perhaps you can achieve your goal by using a JTable with a MouseListener placed in a JDialog.
 
Dan Greer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that is the basic idea. I have tried that. The only issue is how do I return the selected value when that JDialog closes so that it can be assigned to an int like a JOptionPane can?
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use a JList or JTable, and if these are in a modal dialog (either JDialog or JOptionPane), then these objects (the JList or JTable) are still available for querying after the dialog closes, and you should be able to find the selected index of the list/table via standard techniques (i.e., getSelectedIndex()).
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to Swing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic