[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2015-02-12
4
Medium Priority
?
97 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:Christopher Schene
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 23

Accepted Solution

by:
Michael Fowler earned 2000 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:Christopher Schene
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:Christopher Schene
ID: 40608104
Here is my solution based off your answer: works!
solution.java
0
 

Author Closing Comment

by:Christopher Schene
ID: 40608106
Thanks!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.
Suggested Courses

650 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