package com.tutego.insel.ui.list;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class JComboBoxDemo
{
  public static void main( String[] args )
  {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

    String[] lang = {
      "Patronengurt", "Hausnummer", "Schmetterling", "Sphinx", "Anbetung",
      "Ende"
    };

    // First JComboBox

    JComboBox combo1 = new JComboBox();

    for ( String s : lang )
      combo1.addItem( s );
    
    frame.add( combo1, BorderLayout.LINE_START );

    combo1.addActionListener( new ActionListener() {
      public void actionPerformed( ActionEvent e )
      {
        System.out.println( e );
        JComboBox selectedChoice = (JComboBox) e.getSource();
        if ( selectedChoice.getSelectedItem().equals( "Ende" ) )
          System.exit( 0 );
      }
    } );

    // Second JComboBox

    JComboBox combo2 = new JComboBox( lang );

    combo2.setEditable( true );
    combo2.setSelectedItem( "Sphinx" );
    combo2.setMaximumRowCount( 4 );

    frame.add( combo2, BorderLayout.LINE_END );

    frame.pack();
    frame.setVisible( true );
  }
}

