FileDocCategorySizeDatePackage
ComboPanel.javaAPI DocExample768Tue Nov 27 14:24:50 GMT 2001None

ComboPanel.java

//SwingDemo example from "Java 2 Complete" publisher Sybex[1999]



import java.awt.event.*;
import javax.swing.*;

public class ComboPanel extends JPanel 
{
	private JTextField log;
	final static String[] treasure = {"Gold", "Silver",
				"Diamonds", "Rubies", "Emeralds",
				"Sapphires", "Chocolate"};

	public ComboPanel(JTextField tf)
	{
		this.log = tf;

		// construct. Has to be final for inner class to access
		final JComboBox combo=new JComboBox(treasure);
		combo.setMaximumRowCount(5);
		
		// combo box sends item events
		combo.addItemListener(new ItemListener(){
			public void itemStateChanged(ItemEvent e)
				{
				   log.setText("Combo: " + combo.getSelectedItem());
				}
		});
		
		add(combo);
	}
	
} // end class