1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to add multiple combo boxes to a single java program

Discussion in 'Java' started by luettke10, Apr 14, 2010.

  1. luettke10

    luettke10 New Member

    Joined:
    Mar 30, 2010
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    How do you add multiple combo boxes to a single java program? If you could give me the source code I could add the items I want into the dropdown list.
     
  2. satyedra pal

    satyedra pal New Member

    Joined:
    Mar 26, 2010
    Messages:
    93
    Likes Received:
    1
    Trophy Points:
    0
    ComboBox in java is created by Choice class.ComboBox suggest to the user for selecting one choice string depend on user choice from the giving alternatives.
    We can create ComboBox in Java by using following program.
    Code:
    import java.awt.*;
    import java.awt.event.*;
    public class comboboxdemo
    {
      public static void main(String[] args) 
    {
        Frame frame=new Frame("Combobox");
        Label str=new Label("Here is a ComboBox:");
        Choice comb1=new Choice();
        Choice comb2=new Choice();
        frame.add(str);
        frame.add(comb1);
        frame.add(comb2);
        comb1.add("INDIA");
        comb1.add("JAPAN");
        comb1.add("USA");
        comb2.add("INDIA");
        comb2.add("JAPAN");
        comb2.add("USA");
        frame.setLayout(new FlowLayout());
        frame.setSize(300,200);
        frame.setVisible(true);
       
        }
       }
     
    Last edited by a moderator: Apr 15, 2010
  3. luettke10

    luettke10 New Member

    Joined:
    Mar 30, 2010
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    Thank you very much for you help but now I need to know how to change the positions of the combo boxes.
     
  4. satyedra pal

    satyedra pal New Member

    Joined:
    Mar 26, 2010
    Messages:
    93
    Likes Received:
    1
    Trophy Points:
    0
    Hi luettke10,
    You can set the position of the Combo Boxs by using layout manager.Layout manager is used for arranging the java component.
     
  5. luettke10

    luettke10 New Member

    Joined:
    Mar 30, 2010
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    How can you add pictures to a combo box for each of the choices?
     
  6. satyedra pal

    satyedra pal New Member

    Joined:
    Mar 26, 2010
    Messages:
    93
    Likes Received:
    1
    Trophy Points:
    0
    Java Swing provides more feature or set of GUI components compare to (AWT)Abstract Window Toolkit. Java Swing provides pluggable look and feel that allows applications to have a look and feel that is not related to the underlying platform.
    Through java swing we can find image on button,on textBox and also the roundrect box components.SO by using java swing we can add image on the java COmbo Box with each chice.All the keyword of javaswing starts with 'J' character.
     

Share This Page