javax.swing.plaf.basic

Class BasicComboBoxEditor

public class BasicComboBoxEditor extends Object implements ComboBoxEditor, FocusListener

An editor used by the {@link BasicComboBoxUI} class. This editor uses a {@link JTextField} as the editor component.
Nested Class Summary
static classBasicComboBoxEditor.UIResource
A subclass of {@link BasicComboBoxEditor} that implements the {@link UIResource} interface.
Field Summary
protected JTextFieldeditor
The editor component.
Constructor Summary
BasicComboBoxEditor()
Creates a new BasicComboBoxEditor instance.
Method Summary
voidaddActionListener(ActionListener l)
Adds an {@link ActionListener} to the editor component.
voidfocusGained(FocusEvent e)
This method is called when textfield gains focus.
voidfocusLost(FocusEvent e)
This method is called when textfield loses focus.
ComponentgetEditorComponent()
Returns the component that will be used by the combo box to display and edit the currently selected item in the combo box.
ObjectgetItem()
Returns the text from the editor component.
voidremoveActionListener(ActionListener l)
Removes the {@link ActionListener} from the editor component.
voidselectAll()
Selects all the text in the editor component.
voidsetItem(Object item)
Sets item that should be edited when any editing operation is performed by the user.

Field Detail

editor

protected JTextField editor
The editor component.

Constructor Detail

BasicComboBoxEditor

public BasicComboBoxEditor()
Creates a new BasicComboBoxEditor instance.

Method Detail

addActionListener

public void addActionListener(ActionListener l)
Adds an {@link ActionListener} to the editor component. If the user will edit currently selected item in the textfield and pressEnter, then action will be performed. The actionPerformed of this ActionListener should change the selected item of the comboBox to the newly editted selected item.

Parameters: l the ActionListener responsible for changing selected item of the combo box when it is editted by the user.

focusGained

public void focusGained(FocusEvent e)
This method is called when textfield gains focus. This will enable editing of the selected item.

Parameters: e the FocusEvent describing change in focus.

focusLost

public void focusLost(FocusEvent e)
This method is called when textfield loses focus. If during this time any editting operation was performed by the user, then it will be cancelled and selected item will not be changed.

Parameters: e the FocusEvent describing change in focus

getEditorComponent

public Component getEditorComponent()
Returns the component that will be used by the combo box to display and edit the currently selected item in the combo box.

Returns: The editor component, which is a {@link JTextField} in this case.

getItem

public Object getItem()
Returns the text from the editor component.

Returns: The text from the editor component.

removeActionListener

public void removeActionListener(ActionListener l)
Removes the {@link ActionListener} from the editor component.

Parameters: l the listener to remove.

selectAll

public void selectAll()
Selects all the text in the editor component.

setItem

public void setItem(Object item)
Sets item that should be edited when any editing operation is performed by the user. The value is always equal to the currently selected value in the combo box. Thus whenever a different value is selected from the combo box list then this method should be called to change editing item to the new selected item.

Parameters: item item that is currently selected in the combo box