?
Solved

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

Posted on 2015-02-12
4
Medium Priority
?
95 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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

800 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