In this example we are going to see how to use JComboBox Add Items In Java Example
Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import javax.swing.JComboBox; import javax.swing.JFrame; public class Main { public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComboBox jComboBox1 = new JComboBox(); jComboBox1.addItem("Code---"); Object cmboitem = jComboBox1.getSelectedItem(); System.out.println(cmboitem); frame.add(jComboBox1); frame.setSize(300, 200); frame.setVisible(true); } } |
Output: