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