Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2012
    Rep Power

    Default How to put an input dialog box in a combo box program

    I'm making this program that's supposed to act as a menu for specials at a cafe. What I'd like to happen is, when the program is run and the user is done looking through the specials in the combo box and they close it, an input dialog box appears asking which item they picked. I just don't know how to put an input dialog box in.

    I'm very new to Java, and I copied the combo box code from my Java programming book (which is why you see the word "flag" everywhere - the code was originally meant to show flags and their descriptions). I need to make all kinds of programs for a project in my software technology class, which is why I chose a program that I don't fully understand yet. But I just need to figure out how to put an input dialog in. Someone on told me this..

    GUI applications are event driven...
    you display some components an depending the way user interact with them you react to them

    JOptionPane is not such a component. The display of a JOptionPane should be triggered by a JButton, or another situation. You cannot display a JOptionPane in the normal GUI bulding process.
    So.. what kind of resources can I look up that will help me understand how to do this? Or, better yet, can one of you guys help me understand?

    Here's my code:

    Java Code:
    mport java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Scanner;
    public class ComboBoxDemo extends JFrame {
      private double order = 0;
     // Declare an array of Strings for flag titles
     	private String[] flagTitles = {"The Big Easy", "The Sophisticated Ensemble", "The Delectable"};
     // Declare an ImageIcon array for the national flags of 9 countries
     private ImageIcon[] flagImage = {
     	new ImageIcon("Images/bigeasy.jpg"),
     	new ImageIcon("Images/sophisticatedensemble.jpg"),
     	new ImageIcon("Images/thedelectable.jpg"),
     // Declare an array of strings for flag descriptions
    private String[] flagDescription = new String[3];
     // Declare and create a description panel
    private JTextPane Description = new JTextPane(); 
    private JLabel flagImageLabel = new JLabel(); 
    private JComboBox jcbo = new JComboBox(flagTitles);
     // Create a combo box for selecting countries
     public static void main(String[] args) {
     	ComboBoxDemo frame = new ComboBoxDemo();
     	frame.setTitle("Modern Papyrus Cafe Menu");
     	frame.setLocationRelativeTo(null); // Center the frame
     public ComboBoxDemo() {
     // Set text description
     	flagDescription[0] = "1: The Big Easy is, simply put, a big and easy meal!\n" +
    	"It consists of 1 hearty sandwich, stuffed with anything you want\n" +
    	"1 bag of crunchy and savory chips, of your choice\n" +
    	"and 1 large drink, all for $10.99!\n" +
    	"And we've got better news: you can also include any book you choose for 25% off,\n" +
    	"just for buying this meal!";
    	flagDescription[1] = "2: The Sophisticated Ensemble is for those that want to\n" +
     	"take delight in a warmer, sit-by-the-fire kind of meal. It contains:\n " +
     	"1 pastry, donut, brownie, or slice of cake\n" +
     	"and 1 coffee, latte, or tea, all for $8.99!\n" +
     	"To finalize the deal, you may add a book to your purchase for 15% off!";
    	flagDescription[2] = "3: The Delectable is for the sweet tooth! You may have\n" +
    	"1 milkshake, smoothie, or hot chocolate\n" +
    	"and 1 pastry, donut, brownie, or slice of cake, all for $7.99!\n" +
    	"To sweeten the deal, you may add a book to your purchase for 15% off!";
    	 // Set the first country (Canada) for display
    	Description.setPreferredSize(new Dimension(400,300));
    	flagImageLabel.setPreferredSize(new Dimension(300,200));
     // Add combo box and description panel to the list
     	 add(jcbo, BorderLayout.NORTH);
     	 add(Description, BorderLayout.CENTER);
    	 add(flagImageLabel, BorderLayout.WEST);
     // Register listener
     	jcbo.addItemListener(new ItemListener() {
     /** Handle item selection */
     		public void itemStateChanged(ItemEvent e) {
     /** Set display information on the description panel */
     public void setDisplay(int index) {

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Rep Power

    Default Re: How to put an input dialog box in a combo box program

    You cannot display a JOptionPane in the normal GUI bulding process.
    Sure you can. JOptionPane (Java Platform SE 6)

    Look at the showInputDialog() method and some of the others. You can pop up an JOptionPane any time!

Similar Threads

  1. Replies: 4
    Last Post: 04-28-2012, 12:13 AM
  2. Help with Int and JOption Input dialog
    By stephanie904 in forum New To Java
    Replies: 1
    Last Post: 02-29-2012, 01:22 AM
  3. How to create custom Input Dialog
    By Bab in forum SWT / JFace
    Replies: 2
    Last Post: 08-02-2009, 12:21 PM
  4. JOptionPane - input dialog
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-17-2007, 09:09 AM
  5. Multiple Line Input Dialog Box
    By johnt in forum AWT / Swing
    Replies: 2
    Last Post: 05-31-2007, 09:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts