import java.awt.*; import java.awt.event.*; import javax.swing.*; //ActionListener: which item was clicked. public class ComboBox extends JFrame implements ActionListener { JComboBox box; JPanel boxPanel, outputPanel; JTextArea output; String[]boxItems = { "Item 1 ", " Item 2 ", " Item 3 ", " Item 4 ", " Item 5 " }; public ComboBox( ) { Toolkit kit = getToolkit( ); Dimension size = kit.getScreenSize( ); setBounds( size.width/4, size.height/4, size.width/2, size.height/2 ); setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE ); Container contentPane = getContentPane( ); contentPane.setLayout( new GridLayout( 1, 2 ) );//row, column. boxPanel = newJPanel( ); boxPanel.setBackground( Color.cyan ); outputPanel = new JPanel( ); outputPanel.setBackground( Color.white ); contentPane.add( boxPanel ); contentPane.add( outputPanel ); outPut = new JTextArea( 1, 10 );//1 row, 10 columns. output.setBorder( Borderfactory.createLineBorder( Color.blue, 5 ) ); //5 pixels width line. output.setEditable( false ); outputPanel.add( output ); box = new JComboBox( boxItems ); //could make several. box.setBorder( BorderFactory.createTitledBorder( "Items" ) ); box.addActionListener( this ); boxPanel.add( box ); //box.setEnabled(false ); //manipulate user use. box.setEditable( true ); //manipulate user use. setVisible( true ); } public void actionPerfomed( ActionEvent e ){ if( e.getSource( ) == box ) { int index = box.getSelectedIndex( ); output.setText( boxItems[ index ] ); } } public static void main( String [] args ){ ComboBox box = new ComboBox( ); } }