1. /*
  2. * @(#)BasicComboBoxEditor.java 1.15 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.plaf.basic;
  8. import javax.swing.*;
  9. import javax.swing.border.*;
  10. import java.io.Serializable;
  11. import java.awt.*;
  12. import java.awt.event.*;
  13. /**
  14. * The default editor for editable combo boxes
  15. *
  16. * @version 1.9 05/09/98
  17. * @author Arnaud Weber
  18. */
  19. public class BasicComboBoxEditor implements ComboBoxEditor,FocusListener {
  20. protected JTextField editor;
  21. public BasicComboBoxEditor() {
  22. editor = new BorderlessTextField("",9);
  23. //editor.addFocusListener(this);
  24. editor.setBorder(null);
  25. }
  26. public Component getEditorComponent() {
  27. return editor;
  28. }
  29. public void setItem(Object anObject) {
  30. if ( anObject != null )
  31. editor.setText(anObject.toString());
  32. else
  33. editor.setText("");
  34. }
  35. public Object getItem() {
  36. return editor.getText();
  37. }
  38. public void selectAll() {
  39. editor.selectAll();
  40. editor.requestFocus();
  41. }
  42. // This used to do something but now it doesn't. It couldn't be
  43. // removed because it would be an API change to do so.
  44. public void focusGained(FocusEvent e) {}
  45. // This used to do something but now it doesn't. It couldn't be
  46. // removed because it would be an API change to do so.
  47. public void focusLost(FocusEvent e) {}
  48. public void addActionListener(ActionListener l) {
  49. editor.addActionListener(l);
  50. }
  51. public void removeActionListener(ActionListener l) {
  52. editor.removeActionListener(l);
  53. }
  54. static class BorderlessTextField extends JTextField {
  55. public BorderlessTextField(String value,int n) {
  56. super(value,n);
  57. }
  58. public void setBorder(Border b) {}
  59. }
  60. /**
  61. * A subclass of BasicComboBoxEditor that implements UIResource.
  62. * BasicComboBoxEditor doesn't implement UIResource
  63. * directly so that applications can safely override the
  64. * cellRenderer property with BasicListCellRenderer subclasses.
  65. * <p>
  66. * <strong>Warning:</strong>
  67. * Serialized objects of this class will not be compatible with
  68. * future Swing releases. The current serialization support is appropriate
  69. * for short term storage or RMI between applications running the same
  70. * version of Swing. A future release of Swing will provide support for
  71. * long term persistence.
  72. */
  73. public static class UIResource extends BasicComboBoxEditor
  74. implements javax.swing.plaf.UIResource {
  75. }
  76. }