FileDocCategorySizeDatePackage
ComboBox.javaAPI DocJMF 2.1.1e4634Mon May 12 12:20:50 BST 2003com.sun.media.ui

ComboBox

public class ComboBox extends Panel implements ItemListener

Fields Summary
TextField
edit
Variables
Button
bPullDown
PullDownList
listWindow
List
list
boolean
mouseIn
Constructors Summary
public ComboBox()
ComboBox Methods


           
    
      
	this(3);
    
public ComboBox(int cols)

	setLayout( new BorderLayout() );
	
	edit = new TextField(cols);
	bPullDown = new Button("...");
	add("Center", edit);
	add("East", bPullDown);

	list = new List(6);
	list.setBackground(Color.white);
	list.addItemListener( this );

	bPullDown.addActionListener( new ActionListener() {
	    public void actionPerformed(ActionEvent ae) {
		pullDown();
	    }
	} );

	bPullDown.addMouseListener( new MouseAdapter() {
	    public void mouseEntered(MouseEvent me) {
		if (listWindow == null)
		    firstTime();
		mouseIn = true;
	    }

	    public void mouseExited(MouseEvent me) {
		mouseIn = false;
	    }
	} );
    
Methods Summary
public voidadd(java.lang.String item)
List Related Methods

	list.add(item);
    
public voidadd(java.lang.String item, int index)

	list.add(item, index);
    
public voidaddActionListener(java.awt.event.ActionListener al)

	edit.addActionListener(al);
    
public voidaddItem(java.lang.String item)

	list.addItem(item);
    
public voidaddItem(java.lang.String item, int index)

	list.addItem(item, index);
    
public voidaddItemListener(java.awt.event.ItemListener il)

	list.addItemListener(il);
    
public voiddelItem(int index)

	list.delItem(index);
    
public voidfirstTime()


	Component frame = this;
	while (!(frame instanceof Frame) && frame != null) {
	    frame = frame.getParent();
	}
	if (frame == null) {
	    System.out.println("No frame found in hierarchy");
	    System.exit(0);
	}
	listWindow = new PullDownList( (Frame) frame, list);
	listWindow.validate();
    
public intgetSelectedIndex()

	return list.getSelectedIndex();
    
public java.lang.StringgetSelectedItem()

	return list.getSelectedItem();
    
public java.lang.StringgetText()
Text Related Methods

	return edit.getText();
    
public voiditemStateChanged(java.awt.event.ItemEvent ie)

	if (ie.getStateChange() == ItemEvent.SELECTED) {
	    String s = list.getSelectedItem();
	    edit.setText(s);
	    edit.selectAll();
	    pullDown();
	}
    
public voidpullDown()

	if (listWindow.isVisible() == false) {
	    listWindow.show(this);
	} else
	    listWindow.setVisible(false);
    
public voidremoveActionListener(java.awt.event.ActionListener al)

	edit.removeActionListener(al);
    
public voidremoveItemListener(java.awt.event.ItemListener il)

	list.removeItemListener(il);
    
public voidselect(int index)

	list.select(index);
	String s = list.getSelectedItem();
	edit.setText(s);
	edit.selectAll();
    
public voidsetEditable(boolean f)

	edit.setEditable(f);