Solved

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

Posted on 2015-02-12
4
89 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:
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: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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
ejb wildfly example 2 110
eclipse console opening separately 2 48
wild fly 8 startup error 2 77
junit example issue 2 54
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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 video teaches viewers about errors in exception handling.
Suggested Courses

737 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