Solved

How do I show a Java ComboBox in a popup dialog?

Posted on 2015-02-12
4
82 Views
Last Modified: 2015-02-13
Hi,

I would like to show a combo box in my Java program but I would like show it in a popup dialog box similar to the way I would show a dialog asking for input.

Any idea how to do that?

I know how to add a combobox to the main screen, but that is not what I want: I need it in a dialog separate from the main window.

Thanks
0
Comment
Question by:cschene
  • 3
4 Comments
 
LVL 23

Accepted Solution

by:
Michael74 earned 500 total points
ID: 40607284
Use showInputDialog

Object[] possibilities = {"ham", "spam", "yam"};
String s = (String)JOptionPane.showInputDialog(
                    frame,
                    "Complete the sentence:\n"
                    + "\"Green eggs and...\"",
                    "Customized Dialog",
                    JOptionPane.PLAIN_MESSAGE,
                    icon,
                    possibilities,
                    "ham");

//If a string was returned, say so.
if ((s != null) && (s.length() > 0)) {
    setLabel("Green eggs and... " + s + "!");
    return;
}

Open in new window

http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html
0
 

Author Comment

by:cschene
ID: 40607333
One question

"Object[] possibilities = {"ham", "spam", "yam"};

I have a variable array that is always different size.

How do I fill the Object in that case with the names of my choices choices
0
 

Author Comment

by:cschene
ID: 40608104
Here is my solution based off your answer: works!
solution.java
0
 

Author Closing Comment

by:cschene
ID: 40608106
Thanks!
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
micro services vs rest web services 16 105
reverse digits of a number using for loop 5 41
Tomcat: Unable to run tomcat service. 2 18
null output 3 25
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question