javax.swing.plaf.basic
public class: BasicComboBoxEditor [javadoc |
source]
java.lang.Object
javax.swing.plaf.basic.BasicComboBoxEditor
All Implemented Interfaces:
FocusListener, ComboBoxEditor
Direct Known Subclasses:
MetalComboBoxEditor, UIResource, UIResource
The default editor for editable combo boxes. The editor is implemented as a JTextField.
- author:
Arnaud - Weber
- author:
Mark - Davidson
| Nested Class Summary: |
|---|
| static class | BasicComboBoxEditor.BorderlessTextField | |
| public static class | BasicComboBoxEditor.UIResource | A subclass of BasicComboBoxEditor that implements UIResource.
BasicComboBoxEditor doesn't implement UIResource
directly so that applications can safely override the
cellRenderer property with BasicListCellRenderer subclasses.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans package.
Please see {@link java.beans.XMLEncoder}. |
| Field Summary |
|---|
| protected JTextField | editor | |
| Methods from java.lang.Object: |
|---|
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from javax.swing.plaf.basic.BasicComboBoxEditor Detail: |
public void addActionListener(ActionListener l) {
editor.addActionListener(l);
}
|
protected JTextField createEditorComponent() {
JTextField editor = new BorderlessTextField("",9);
editor.setBorder(null);
return editor;
}
Creates the internal editor component. Override this to provide
a custom implementation. |
public void focusGained(FocusEvent e) {
}
|
public void focusLost(FocusEvent e) {
}
|
public Component getEditorComponent() {
return editor;
}
|
public Object getItem() {
Object newValue = editor.getText();
if (oldValue != null && !(oldValue instanceof String)) {
// The original value is not a string. Should return the value in it's
// original type.
if (newValue.equals(oldValue.toString())) {
return oldValue;
} else {
// Must take the value from the editor and get the value and cast it to the new type.
Class cls = oldValue.getClass();
try {
Method method = cls.getMethod("valueOf", new Class[]{String.class});
newValue = method.invoke(oldValue, new Object[] { editor.getText()});
} catch (Exception ex) {
// Fail silently and return the newValue (a String object)
}
}
}
return newValue;
}
|
public void removeActionListener(ActionListener l) {
editor.removeActionListener(l);
}
|
public void selectAll() {
editor.selectAll();
editor.requestFocus();
}
|
public void setItem(Object anObject) {
if ( anObject != null ) {
editor.setText(anObject.toString());
oldValue = anObject;
} else {
editor.setText("");
}
}
Sets the item that should be edited. |