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.
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); } }
Thank you very much for you help but now I need to know how to change the positions of the combo boxes.
Hi luettke10, You can set the position of the Combo Boxs by using layout manager.Layout manager is used for arranging the java component.
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.