How Use the Combo Box With Netbeans GUI

By Jim Campbell

The "JComboBox" in Netbeans displays a list of items for users. The user chooses one of the items in the combo box that submits to your processing form. Netbeans has a graphical interface with a toolbox, so you only need to drag and drop a JComboBox from the toolbox and add the items you want to display without manually creating the code.

Step 1

Open the Netbeans software using the shortcut icon in the Windows program group. Open your desktop or Web project after Netbeans loads.

Step 2

Double-click the Java form you want to use to display the JComboBox. Drag and drop a combo box from the toolbox to the form. Netbeans automatically draws the combo box on the form. The JComboBox control automatically sizes as you add items into the selection area.

Step 3

Double-click the JComboBox to open the Java class file. In this file you dynamically add items to the list.

Step 4

Add the items to the selection list. For instance, the following code adds two color options to the JComboBox:

jcombobox1.addItem("Blue"); jcombobox1.addItem("Orance");

Step 5

Click the "Save" button to save the changes to the Java form. Use your mouse to move the JComboBox around the form to place it in the exact location in which you want the control to display.