-
Enhancement
-
Resolution: Won't Fix
-
P4
-
1.2.2, 1.3.0, 6
-
generic, x86
-
generic, windows_95
Name: krT82822 Date: 03/17/2000
java version "1.3.0rc1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)
If a JComboBox is editable, we are able to set the editor that it uses by
calling its setEditor() method. In order to set the editor component using this
method, one must also subclass the BasicComboBoxEditor or otherwise define our
own ComboBoxEditor class.
While it may sometimes be necessary to define a whole new ComboBoxEditor class,
often all that is needed is to install a subclass of JTextField as our editor
component. To make this easier, the BasicComboBoxEditor should allow us to set
the editor component (as a subclass of JTextField) when we construct it.
(Review ID: 102611)
======================================================================
Suggested fix and JUnit test case follow:
A DESCRIPTION OF THE FIX :
Bug number: 4322996
Bug description: Add facilities to BasicComboBoxEditor to set a custom internal editor.
Diff baseline: Mustang b54.
Diff:
--- BasicComboBoxEditor.java 2005-10-09 22:47:02.714409600 +0200
+++ BasicComboBoxEditor2.java 2005-10-09 22:40:34.175718400 +0200
@@ -33,10 +33,18 @@
editor = new BorderlessTextField("",9);
editor.setBorder(null);
}
+
+ public BasicComboBoxEditor(JTextField editor) {
+ this.editor = editor;
+ }
public Component getEditorComponent() {
return editor;
}
+
+ public void setEditorComponent(JTextField editor) {
+ this.editor = editor;
+ }
/**
* Sets the item that should be edited.
JUnit TESTCASE :
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import javax.swing.JTextField;
import javax.swing.plaf.basic.BasicComboBoxEditor;
import junit.framework.TestCase;
public class TestBasicComboBoxEditor extends TestCase {
public static void main(String[] args) {
junit.swingui.TestRunner.run(TestBasicComboBoxEditor.class);
}
public void testConstructor(){
Class c = BasicComboBoxEditor.class;
boolean found = true;
try {
Constructor ctor = c.getConstructor(new Class[]{JTextField.class});
} catch (NoSuchMethodException e) {
found = false;
}
assertEquals(true, found);
}
public void testEditorSetter(){
Class c = BasicComboBoxEditor.class;
boolean found = true;
try {
Method m = c.getMethod("setEditorComponent", new Class[]{JTextField.class});
} catch (NoSuchMethodException e) {
found = false;
}
assertEquals(true, found);
}
}
FIX FOR BUG NUMBER:
4322996
java version "1.3.0rc1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)
If a JComboBox is editable, we are able to set the editor that it uses by
calling its setEditor() method. In order to set the editor component using this
method, one must also subclass the BasicComboBoxEditor or otherwise define our
own ComboBoxEditor class.
While it may sometimes be necessary to define a whole new ComboBoxEditor class,
often all that is needed is to install a subclass of JTextField as our editor
component. To make this easier, the BasicComboBoxEditor should allow us to set
the editor component (as a subclass of JTextField) when we construct it.
(Review ID: 102611)
======================================================================
Suggested fix and JUnit test case follow:
A DESCRIPTION OF THE FIX :
Bug number: 4322996
Bug description: Add facilities to BasicComboBoxEditor to set a custom internal editor.
Diff baseline: Mustang b54.
Diff:
--- BasicComboBoxEditor.java 2005-10-09 22:47:02.714409600 +0200
+++ BasicComboBoxEditor2.java 2005-10-09 22:40:34.175718400 +0200
@@ -33,10 +33,18 @@
editor = new BorderlessTextField("",9);
editor.setBorder(null);
}
+
+ public BasicComboBoxEditor(JTextField editor) {
+ this.editor = editor;
+ }
public Component getEditorComponent() {
return editor;
}
+
+ public void setEditorComponent(JTextField editor) {
+ this.editor = editor;
+ }
/**
* Sets the item that should be edited.
JUnit TESTCASE :
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import javax.swing.JTextField;
import javax.swing.plaf.basic.BasicComboBoxEditor;
import junit.framework.TestCase;
public class TestBasicComboBoxEditor extends TestCase {
public static void main(String[] args) {
junit.swingui.TestRunner.run(TestBasicComboBoxEditor.class);
}
public void testConstructor(){
Class c = BasicComboBoxEditor.class;
boolean found = true;
try {
Constructor ctor = c.getConstructor(new Class[]{JTextField.class});
} catch (NoSuchMethodException e) {
found = false;
}
assertEquals(true, found);
}
public void testEditorSetter(){
Class c = BasicComboBoxEditor.class;
boolean found = true;
try {
Method m = c.getMethod("setEditorComponent", new Class[]{JTextField.class});
} catch (NoSuchMethodException e) {
found = false;
}
assertEquals(true, found);
}
}
FIX FOR BUG NUMBER:
4322996
- duplicates
-
JDK-4346934 provide DefaultComboBoxEditor implementation
-
- Closed
-