-
Enhancement
-
Resolution: Unresolved
-
P5
-
None
-
1.4.2, 6
-
Fix Understood
-
generic, x86
-
generic, windows_2000
Name: rmT116609 Date: 10/23/2003
A DESCRIPTION OF THE REQUEST :
DefaultCellEditor currently supports only JTextField, JCheckBox, and JComboBox. Although it has a rather abstract architecture using an EditorDelegate which encapsulates the actual component, it is not possible to supply any other component, e.g. JSpinner.
JUSTIFICATION :
It would be good to have JSpinner as cell editors in tables or trees for numbers or date types. In addition a more general approach for arbitrary GUI components is desirable.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Please refactor javax.swing.DefaultCellEditor such that the following constructor is available
protected DefaultCellEditor(EditorDelegate delegate[, Component component])
You may have to make EditorDelegate public and might enhance it by a method
getComponent().
To support an additional feature you may provide the constructor
public DefaultCellEditor(final java.beans.PropertyEditor E)
{
this(new EditorDelegate()
{
public Object getCellEditorValue() {
return E.getValue();
}
public void setValue(Object value) {
E.setValue(value);
}
public Component getComponent() {
return E.getCustomEditor();
}
});
}
ACTUAL -
The requested feature is not available. To get it you have to duplicate the source code of DefaultCellEditor
(Incident Review ID: 215637)
======================================================================
Contrubuted by community member leouser:
A DESCRIPTION OF THE FIX :
BUGID 4942687 Allow for additional component types in javax.swing.DefaultCellEditor.
FILES AFFECTED: javax.swing.DefaultCellEditor.
JDK VERSION
jdk-6-rc-bin-b64-linux-i586-15_dec_2005.bin
Discusion(embeded in test case as well):
/**
* BUGID 4942687 Allow for additional component types in javax.swing.DefaultCellEditor.
* This RFE adds 2 things: a constructor for JSpinner
* and a protected constructor for a JComponent. The goal for the first
* is to provide coverage for components that provide simple interfaces for
* manipulating values. These will be simple to use from now on. The 2nd
* is to make this thing extensible for other types of JComponent subclasses
* that have not been envisioned to be useful. Maybe I want to make a megawidget
* and use that for the Editor. Now with the protected constructor I can
* do so. This class was locked into 3 widgets because of a lack of this
* type of constructor forcing people to write their TableCellEditor and
* TreeCellEditors from scratch if they didn't fit into the simple mold.
*
* It is a shame that the EditorDelegate was not made static, it forces
* us to subclass DefaultCellEditor when just subclassing EditorDelegate
* would have been ok. We can't reverse this decision because there
* are possible subclasses out there that have subclassed and implemented
* EditorDelegate similiar to the style of what is used in the DefaultCellEditor
* source. I guess this is an example of why static classes are better than
* just plain old nested classes, their generally more useful.
*
* BENEFITS: new editors available, can actually subclass and extend beyond
* the visions of the implementators. Luckily adding a protected constructor
* makes it a viable option for subclassing, almost instantly. All the
* fields are protected and accessible.
*
* ANTI-RATIONALE: well, we can't really break anything. Were just adding
* constructors, which are not overridable methods.
*
* TESTING STRATEGY:
* Create a JTable and populate it with integers. Set the editor for all cells
* to be a JSpinner. Edit
* and manipulate values. Subclass DefaultCellEditor to show that the
* new protected constructor can be called.
*
* A NOTE ON JSlider:
* I considered JSlider as an additional component, but really wasn't pleased
* with it. All you could see was a slider and no value feedback. This
* can be implemented by a subclasser now if they want it.
*
* A NOTE ON LISTENERS:
* I have noticed in the other constructors that the widgets are tied
* to action listeners in every case. This listener does not fit in with
* the new component since it doesn't take action listeners. Therefore
* Im unclear as to what they are doing outside of notifying the EditorDelegate
* that an ActionEvent has occured. If need be Ill tie them in somehow.
*
* THINGS I CHOSE NOT TO DO FOR THE BUG REPORT:
* 1. I did make EditorDelegate public because as the test case shows you
* have to subclass DefaultCellEditor to subclass EditorDelegate. Clumsy
* yes but reality.
* 2. I did not add a PropertyEditor to this because I don't see the advantage
* of using this. It adds extra weight to the class and no one may actually
* use this approach. Also getEditorComponent in the interface makes no
* guarantee that it actually has an editor, or that it will use the same
* editor every time. It says "may choose". The DefaultCellEditor references one component for
* its editor, its does not query. Also with this approach it is impossible
* to determine what listeners need to be attached to it. Just sticking an
* editor in the JTable does not mean it will work right. This seems a path
* to disappointment a frustration. New editors must be dealt with not on
* a generic level but at a specific level.
*
* FILES AFFECTED: javax.swing.DefaultCellEditor.
* JDK VERSION
* jdk-6-rc-bin-b64-linux-i586-15_dec_2005.bin
*
* test ran succesfully on a SUSE 7.3 Linux distribution
*
* Brian Harry
* ###@###.###
* Jan 22, 2006
*/
UNIFIED DIFF:
--- /home/nstuff/java6/jdk1.6.0/javax/swing/DefaultCellEditor.java Thu Dec 15 02:17:34 2005
+++ /home/javarefs/javax/swing/DefaultCellEditor.java Sun Jan 22 11:04:18 2006
@@ -144,6 +144,35 @@
}
/**
+ * Constructs a <code>DefaultCellEditor</code> that uses a <code>JSpinner</code>.
+ *
+ * @param spinner a <code>JSpinner</code> object
+ */
+ public DefaultCellEditor(final JSpinner spinner){
+ editorComponent = spinner;
+ this.clickCountToStart = 2;
+ delegate = new EditorDelegate(){
+ public void setValue(Object value){
+ spinner.setValue(value != null? value:"");
+ }
+
+ public Object getCellEditorValue(){
+ return spinner.getValue();
+ }
+ };
+ }
+
+ /**
+ * Hook to allow subclassing for different types of <code>JComponent<code>
+ * objects.
+ *
+ * @param jc a <code>JComponent</code> object
+ */
+ protected DefaultCellEditor(JComponent jc){
+ editorComponent = jc;
+ }
+
+ /**
* Returns a reference to the editor component.
*
* @return the editor <code>Component</code>
JUnit TESTCASE :
import javax.swing.*;
import javax.swing.table.*;
import static java.lang.System.out;
/**
* BUGID 4942687 Allow for additional component types in javax.swing.DefaultCellEditor.
* This RFE adds 2 things: a constructor for JSpinner
* and a protected constructor for a JComponent. The goal for the first
* is to provide coverage for components that provide simple interfaces for
* manipulating values. These will be simple to use from now on. The 2nd
* is to make this thing extensible for other types of JComponent subclasses
* that have not been envisioned to be useful. Maybe I want to make a megawidget
* and use that for the Editor. Now with the protected constructor I can
* do so. This class was locked into 3 widgets because of a lack of this
* type of constructor forcing people to write their TableCellEditor and
* TreeCellEditors from scratch if they didn't fit into the simple mold.
*
* It is a shame that the EditorDelegate was not made static, it forces
* us to subclass DefaultCellEditor when just subclassing EditorDelegate
* would have been ok. We can't reverse this decision because there
* are possible subclasses out there that have subclassed and implemented
* EditorDelegate similiar to the style of what is used in the DefaultCellEditor
* source. I guess this is an example of why static classes are better than
* just plain old nested classes, their generally more useful.
*
* BENEFITS: new editors available, can actually subclass and extend beyond
* the visions of the implementators. Luckily adding a protected constructor
* makes it a viable option for subclassing, almost instantly. All the
* fields are protected and accessible.
*
* ANTI-RATIONALE: well, we can't really break anything. Were just adding
* constructors, which are not overridable methods.
*
* TESTING STRATEGY:
* Create a JTable and populate it with integers. Set the editor for all cells
* to be a JSpinner. Edit
* and manipulate values. Subclass DefaultCellEditor to show that the
* new protected constructor can be called.
*
* A NOTE ON JSlider:
* I considered JSlider as an additional component, but really wasn't pleased
* with it. All you could see was a slider and no value feedback. This
* can be implemented by a subclasser now if they want it.
*
* A NOTE ON LISTENERS:
* I have noticed in the other constructors that the widgets are tied
* to action listeners in every case. This listener does not fit in with
* the new component since it doesn't take action listeners. Therefore
* Im unclear as to what they are doing outside of notifying the EditorDelegate
* that an ActionEvent has occured. If need be Ill tie them in somehow.
*
* THINGS I CHOSE NOT TO DO FOR THE BUG REPORT:
* 1. I did make EditorDelegate public because as the test case shows you
* have to subclass DefaultCellEditor to subclass EditorDelegate. Clumsy
* yes but reality.
* 2. I did not add a PropertyEditor to this because I don't see the advantage
* of using this. It adds extra weight to the class and no one may actually
* use this approach. Also getEditorComponent in the interface makes no
* guarantee that it actually has an editor, or that it will use the same
* editor every time. It says "may choose". The DefaultCellEditor references one component for
* its editor, its does not query. Also with this approach it is impossible
* to determine what listeners need to be attached to it. Just sticking an
* editor in the JTable does not mean it will work right. This seems a path
* to disappointment a frustration. New editors must be dealt with not on
* a generic level but at a specific level.
*
* FILES AFFECTED: javax.swing.DefaultCellEditor.
* JDK VERSION
* jdk-6-rc-bin-b64-linux-i586-15_dec_2005.bin
*
* test ran succesfully on a SUSE 7.3 Linux distribution
*
* Brian Harry
* ###@###.###
* Jan 22, 2006
*/
public class Test4942687{
public static class ShowSubclass extends DefaultCellEditor{
public ShowSubclass(JTable jt){
super(jt);///can't pass an ED instance in because we haven't called the superclass yet... !
}
public class ED extends EditorDelegate{}
}
public void startGUI(){
JFrame jf = new JFrame();
Object[][] values = new Object[10][10];
Object[] names = new Object[10];
for(int i = 0; i < 10; i++){
names[i] = String.valueOf(i);
for(int i2 = 0; i2 < 10; i2++)
values[i][i2] = i2;
}
JTable jt = new JTable(values, names);
JSpinner js = new JSpinner();
DefaultCellEditor dce = new DefaultCellEditor(js);
TableColumnModel tcm = jt.getColumnModel();
for(int i = 0; i < 10; i++)
tcm.getColumn(i).setCellEditor(dce);
JScrollPane jsp = new JScrollPane(jt);
jf.add(jsp);
jf.pack();
jf.setVisible(true);
}
public static void main(String ... args){
Runnable run = new Runnable(){
public void run(){
Test4942687 t = new Test4942687();
t.startGUI();
}
};
SwingUtilities.invokeLater(run);
}
}
FIX FOR BUG NUMBER:
4942687
A DESCRIPTION OF THE REQUEST :
DefaultCellEditor currently supports only JTextField, JCheckBox, and JComboBox. Although it has a rather abstract architecture using an EditorDelegate which encapsulates the actual component, it is not possible to supply any other component, e.g. JSpinner.
JUSTIFICATION :
It would be good to have JSpinner as cell editors in tables or trees for numbers or date types. In addition a more general approach for arbitrary GUI components is desirable.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Please refactor javax.swing.DefaultCellEditor such that the following constructor is available
protected DefaultCellEditor(EditorDelegate delegate[, Component component])
You may have to make EditorDelegate public and might enhance it by a method
getComponent().
To support an additional feature you may provide the constructor
public DefaultCellEditor(final java.beans.PropertyEditor E)
{
this(new EditorDelegate()
{
public Object getCellEditorValue() {
return E.getValue();
}
public void setValue(Object value) {
E.setValue(value);
}
public Component getComponent() {
return E.getCustomEditor();
}
});
}
ACTUAL -
The requested feature is not available. To get it you have to duplicate the source code of DefaultCellEditor
(Incident Review ID: 215637)
======================================================================
Contrubuted by community member leouser:
A DESCRIPTION OF THE FIX :
BUGID 4942687 Allow for additional component types in javax.swing.DefaultCellEditor.
FILES AFFECTED: javax.swing.DefaultCellEditor.
JDK VERSION
jdk-6-rc-bin-b64-linux-i586-15_dec_2005.bin
Discusion(embeded in test case as well):
/**
* BUGID 4942687 Allow for additional component types in javax.swing.DefaultCellEditor.
* This RFE adds 2 things: a constructor for JSpinner
* and a protected constructor for a JComponent. The goal for the first
* is to provide coverage for components that provide simple interfaces for
* manipulating values. These will be simple to use from now on. The 2nd
* is to make this thing extensible for other types of JComponent subclasses
* that have not been envisioned to be useful. Maybe I want to make a megawidget
* and use that for the Editor. Now with the protected constructor I can
* do so. This class was locked into 3 widgets because of a lack of this
* type of constructor forcing people to write their TableCellEditor and
* TreeCellEditors from scratch if they didn't fit into the simple mold.
*
* It is a shame that the EditorDelegate was not made static, it forces
* us to subclass DefaultCellEditor when just subclassing EditorDelegate
* would have been ok. We can't reverse this decision because there
* are possible subclasses out there that have subclassed and implemented
* EditorDelegate similiar to the style of what is used in the DefaultCellEditor
* source. I guess this is an example of why static classes are better than
* just plain old nested classes, their generally more useful.
*
* BENEFITS: new editors available, can actually subclass and extend beyond
* the visions of the implementators. Luckily adding a protected constructor
* makes it a viable option for subclassing, almost instantly. All the
* fields are protected and accessible.
*
* ANTI-RATIONALE: well, we can't really break anything. Were just adding
* constructors, which are not overridable methods.
*
* TESTING STRATEGY:
* Create a JTable and populate it with integers. Set the editor for all cells
* to be a JSpinner. Edit
* and manipulate values. Subclass DefaultCellEditor to show that the
* new protected constructor can be called.
*
* A NOTE ON JSlider:
* I considered JSlider as an additional component, but really wasn't pleased
* with it. All you could see was a slider and no value feedback. This
* can be implemented by a subclasser now if they want it.
*
* A NOTE ON LISTENERS:
* I have noticed in the other constructors that the widgets are tied
* to action listeners in every case. This listener does not fit in with
* the new component since it doesn't take action listeners. Therefore
* Im unclear as to what they are doing outside of notifying the EditorDelegate
* that an ActionEvent has occured. If need be Ill tie them in somehow.
*
* THINGS I CHOSE NOT TO DO FOR THE BUG REPORT:
* 1. I did make EditorDelegate public because as the test case shows you
* have to subclass DefaultCellEditor to subclass EditorDelegate. Clumsy
* yes but reality.
* 2. I did not add a PropertyEditor to this because I don't see the advantage
* of using this. It adds extra weight to the class and no one may actually
* use this approach. Also getEditorComponent in the interface makes no
* guarantee that it actually has an editor, or that it will use the same
* editor every time. It says "may choose". The DefaultCellEditor references one component for
* its editor, its does not query. Also with this approach it is impossible
* to determine what listeners need to be attached to it. Just sticking an
* editor in the JTable does not mean it will work right. This seems a path
* to disappointment a frustration. New editors must be dealt with not on
* a generic level but at a specific level.
*
* FILES AFFECTED: javax.swing.DefaultCellEditor.
* JDK VERSION
* jdk-6-rc-bin-b64-linux-i586-15_dec_2005.bin
*
* test ran succesfully on a SUSE 7.3 Linux distribution
*
* Brian Harry
* ###@###.###
* Jan 22, 2006
*/
UNIFIED DIFF:
--- /home/nstuff/java6/jdk1.6.0/javax/swing/DefaultCellEditor.java Thu Dec 15 02:17:34 2005
+++ /home/javarefs/javax/swing/DefaultCellEditor.java Sun Jan 22 11:04:18 2006
@@ -144,6 +144,35 @@
}
/**
+ * Constructs a <code>DefaultCellEditor</code> that uses a <code>JSpinner</code>.
+ *
+ * @param spinner a <code>JSpinner</code> object
+ */
+ public DefaultCellEditor(final JSpinner spinner){
+ editorComponent = spinner;
+ this.clickCountToStart = 2;
+ delegate = new EditorDelegate(){
+ public void setValue(Object value){
+ spinner.setValue(value != null? value:"");
+ }
+
+ public Object getCellEditorValue(){
+ return spinner.getValue();
+ }
+ };
+ }
+
+ /**
+ * Hook to allow subclassing for different types of <code>JComponent<code>
+ * objects.
+ *
+ * @param jc a <code>JComponent</code> object
+ */
+ protected DefaultCellEditor(JComponent jc){
+ editorComponent = jc;
+ }
+
+ /**
* Returns a reference to the editor component.
*
* @return the editor <code>Component</code>
JUnit TESTCASE :
import javax.swing.*;
import javax.swing.table.*;
import static java.lang.System.out;
/**
* BUGID 4942687 Allow for additional component types in javax.swing.DefaultCellEditor.
* This RFE adds 2 things: a constructor for JSpinner
* and a protected constructor for a JComponent. The goal for the first
* is to provide coverage for components that provide simple interfaces for
* manipulating values. These will be simple to use from now on. The 2nd
* is to make this thing extensible for other types of JComponent subclasses
* that have not been envisioned to be useful. Maybe I want to make a megawidget
* and use that for the Editor. Now with the protected constructor I can
* do so. This class was locked into 3 widgets because of a lack of this
* type of constructor forcing people to write their TableCellEditor and
* TreeCellEditors from scratch if they didn't fit into the simple mold.
*
* It is a shame that the EditorDelegate was not made static, it forces
* us to subclass DefaultCellEditor when just subclassing EditorDelegate
* would have been ok. We can't reverse this decision because there
* are possible subclasses out there that have subclassed and implemented
* EditorDelegate similiar to the style of what is used in the DefaultCellEditor
* source. I guess this is an example of why static classes are better than
* just plain old nested classes, their generally more useful.
*
* BENEFITS: new editors available, can actually subclass and extend beyond
* the visions of the implementators. Luckily adding a protected constructor
* makes it a viable option for subclassing, almost instantly. All the
* fields are protected and accessible.
*
* ANTI-RATIONALE: well, we can't really break anything. Were just adding
* constructors, which are not overridable methods.
*
* TESTING STRATEGY:
* Create a JTable and populate it with integers. Set the editor for all cells
* to be a JSpinner. Edit
* and manipulate values. Subclass DefaultCellEditor to show that the
* new protected constructor can be called.
*
* A NOTE ON JSlider:
* I considered JSlider as an additional component, but really wasn't pleased
* with it. All you could see was a slider and no value feedback. This
* can be implemented by a subclasser now if they want it.
*
* A NOTE ON LISTENERS:
* I have noticed in the other constructors that the widgets are tied
* to action listeners in every case. This listener does not fit in with
* the new component since it doesn't take action listeners. Therefore
* Im unclear as to what they are doing outside of notifying the EditorDelegate
* that an ActionEvent has occured. If need be Ill tie them in somehow.
*
* THINGS I CHOSE NOT TO DO FOR THE BUG REPORT:
* 1. I did make EditorDelegate public because as the test case shows you
* have to subclass DefaultCellEditor to subclass EditorDelegate. Clumsy
* yes but reality.
* 2. I did not add a PropertyEditor to this because I don't see the advantage
* of using this. It adds extra weight to the class and no one may actually
* use this approach. Also getEditorComponent in the interface makes no
* guarantee that it actually has an editor, or that it will use the same
* editor every time. It says "may choose". The DefaultCellEditor references one component for
* its editor, its does not query. Also with this approach it is impossible
* to determine what listeners need to be attached to it. Just sticking an
* editor in the JTable does not mean it will work right. This seems a path
* to disappointment a frustration. New editors must be dealt with not on
* a generic level but at a specific level.
*
* FILES AFFECTED: javax.swing.DefaultCellEditor.
* JDK VERSION
* jdk-6-rc-bin-b64-linux-i586-15_dec_2005.bin
*
* test ran succesfully on a SUSE 7.3 Linux distribution
*
* Brian Harry
* ###@###.###
* Jan 22, 2006
*/
public class Test4942687{
public static class ShowSubclass extends DefaultCellEditor{
public ShowSubclass(JTable jt){
super(jt);///can't pass an ED instance in because we haven't called the superclass yet... !
}
public class ED extends EditorDelegate{}
}
public void startGUI(){
JFrame jf = new JFrame();
Object[][] values = new Object[10][10];
Object[] names = new Object[10];
for(int i = 0; i < 10; i++){
names[i] = String.valueOf(i);
for(int i2 = 0; i2 < 10; i2++)
values[i][i2] = i2;
}
JTable jt = new JTable(values, names);
JSpinner js = new JSpinner();
DefaultCellEditor dce = new DefaultCellEditor(js);
TableColumnModel tcm = jt.getColumnModel();
for(int i = 0; i < 10; i++)
tcm.getColumn(i).setCellEditor(dce);
JScrollPane jsp = new JScrollPane(jt);
jf.add(jsp);
jf.pack();
jf.setVisible(true);
}
public static void main(String ... args){
Runnable run = new Runnable(){
public void run(){
Test4942687 t = new Test4942687();
t.startGUI();
}
};
SwingUtilities.invokeLater(run);
}
}
FIX FOR BUG NUMBER:
4942687