-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
1.3.0
-
Fix Understood
-
generic
-
generic
Name: ssT124754 Date: 01/31/2001
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
I previously submitted this as # 111909
The KeySelection manager of the JCombo doesn't work if you
use a ListCellRenderer. It only works for objects with toString() (as the
defaultcellrenderer. To get all my combos working for every type of object
i put in the combos (one combo for one type) i must make a CellRenderer and a
Keyselection manager. The only thing i do there is point to the right name of
the objects (calling getName() instead of toString())
So i proposed a different one: Setting one Interface that is used by both:
The CellRenderer and the KeySelection manager for getting the String of the
object.
The previous bug/ease of use
Hi,
When i add objects to a Listmodel (or combomodel) that aren't just strings but
complete objects. To get the value that must be shown of that object i can do 2
things;
implement the toString() of that object
or
Make my own ListCellRenderer to call the right methods for that object.
What way is the best? or cleanest?
I think most of you say: ListCellRenderer (aren't you?)
But now i give you the source of the KeySelectionManager that JCombo uses to
select
the item with a char:
for ( i = ++currentSelection, c = aModel.getSize() ; i < c ; i++ ) {
v = aModel.getElementAt(i).toString().toLowerCase();
if ( v.length() > 0 && v.charAt(0) == aKey )
return i;
}
AHHHHHRGHH just calling toString()!!!!
that means that only setting a ListCellRenderer is complete useless. You must
make a KeySelectionManager
for every ListCellRenderer you make!
Why didn't Sun combine those 2?
example:
A JList (and JCombo) wants another interface:
ListCellString with a method: public String getDisplayString(listItem);
The getListCellRendererComponent of the ListCellRenderer interface
gets one more parameter: The ListCellString
The Default Behaviour of the ListCellRenderer(s) is calling the getDisplayString
(Object) of the
ListCellString interface to get the displayable String.
This ListCellString interface is then also used in the
DefaultKeySelectionManager for getting the String
that is displayed in the JList/JCombo.
Then the only thing one has to do is setting a ListCellString object in the
JList/JCombo if
you only want to say: This is the string that must be displayed of that object.
workaround : Implementing for every object you display in a list a KeySelection
and a
ListCellRenderer. (and setting those for every combo/list you use!!)
Why not just implement one simple Interface as descibed above.
(Review ID: 111960)
======================================================================
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
I previously submitted this as # 111909
The KeySelection manager of the JCombo doesn't work if you
use a ListCellRenderer. It only works for objects with toString() (as the
defaultcellrenderer. To get all my combos working for every type of object
i put in the combos (one combo for one type) i must make a CellRenderer and a
Keyselection manager. The only thing i do there is point to the right name of
the objects (calling getName() instead of toString())
So i proposed a different one: Setting one Interface that is used by both:
The CellRenderer and the KeySelection manager for getting the String of the
object.
The previous bug/ease of use
Hi,
When i add objects to a Listmodel (or combomodel) that aren't just strings but
complete objects. To get the value that must be shown of that object i can do 2
things;
implement the toString() of that object
or
Make my own ListCellRenderer to call the right methods for that object.
What way is the best? or cleanest?
I think most of you say: ListCellRenderer (aren't you?)
But now i give you the source of the KeySelectionManager that JCombo uses to
select
the item with a char:
for ( i = ++currentSelection, c = aModel.getSize() ; i < c ; i++ ) {
v = aModel.getElementAt(i).toString().toLowerCase();
if ( v.length() > 0 && v.charAt(0) == aKey )
return i;
}
AHHHHHRGHH just calling toString()!!!!
that means that only setting a ListCellRenderer is complete useless. You must
make a KeySelectionManager
for every ListCellRenderer you make!
Why didn't Sun combine those 2?
example:
A JList (and JCombo) wants another interface:
ListCellString with a method: public String getDisplayString(listItem);
The getListCellRendererComponent of the ListCellRenderer interface
gets one more parameter: The ListCellString
The Default Behaviour of the ListCellRenderer(s) is calling the getDisplayString
(Object) of the
ListCellString interface to get the displayable String.
This ListCellString interface is then also used in the
DefaultKeySelectionManager for getting the String
that is displayed in the JList/JCombo.
Then the only thing one has to do is setting a ListCellString object in the
JList/JCombo if
you only want to say: This is the string that must be displayed of that object.
workaround : Implementing for every object you display in a list a KeySelection
and a
ListCellRenderer. (and setting those for every combo/list you use!!)
Why not just implement one simple Interface as descibed above.
(Review ID: 111960)
======================================================================