Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6179357
Votes 11
Synopsis Request interface javax.swing.tree.TreeModel to have a generic type for nodes
Category java:classes_swing
Reported Against
Release Fixed
State 3-Accepted, request for enhancement
Priority: 4-Low
Related Bugs 6350746
Submit Date 14-OCT-2004
Description
A DESCRIPTION OF THE REQUEST :
I request that the interface javax.swing.tree.TreeModel have a generic type for the nodes.

Here is my suggested generic interface :

public interface TreeModel<N extends Object>
{
    public N getRoot();
    public N getChild(N parent, int index);
    public int getChildCount(N parent);
    public boolean isLeaf(N node);
    public void valueForPathChanged(TreePath path, N newValue);
    public int getIndexOfChild(N parent, N child);
    void addTreeModelListener(TreeModelListener l);
    void removeTreeModelListener(TreeModelListener l);
}



JUSTIFICATION :
The interface javax.swing.tree.TreeModel is the representation of something that can virtually be seen as a container, so it seem logic to apply the generic changes that were applied to the collection to the TreeModel also.

The TreeModel implementations actually need to be implemented in the old fashion, with a lot of cast from the type Object to the type that the imlementor suppose the nodes are really (and they pray that the JTree will not call the model with another type of node that the one that the programmer assume).

I think this is a  customer  candidate for the generics.

Note : perhaps the same request can be applied to the table models, list models, etc ...
  xxxxx@xxxxx   10/14/04 19:40 GMT
Work Around
N/A
Evaluation
TreeModel and TreeNode both could use some sort of generification.
  xxxxx@xxxxx   2005-07-13 18:08:34 GMT
Comments
  
  Include a link with my name & email   

Submitted On 18-OCT-2004
karmaGfa
I also suggest that you add a the generic type of the nodes of the tree in the JTree, so that only the TreeModel<N> will be used in a JTree<N>.


Submitted On 19-OCT-2004
karmaGfa
I would like to correct also :

    void addTreeModelListener(TreeModelListener l);
    void removeTreeModelListener(TreeModelListener l);


should be something like :

    void addTreeModelListener(TreeModelListener<N> l);
    void removeTreeModelListener(TreeModelListener<N> l);


Submitted On 28-DEC-2004
Puce
I also suggest to change the other components and models (like ListModel, CombBoxModel etc.) to use generic types instead of Object.


Submitted On 27-AUG-2005
karmaGfa
Since it is easy to do the changes and since there seems to not be any cons to this RFE, I wonder why it takes so long to have those generics integrated with the API.

When will the generification be applied ? Does somebody have plans to make it for whatever version is not ?


Submitted On 27-AUG-2005
karmaGfa
PS: I agree with Puce, it should also be added to the other container-like GUI components.


Submitted On 18-JAN-2007
msundman
Generification isn't exactly rocket science. Howcome it always takes many years for Sun to do even the simplest things?


Submitted On 04-DEC-2007
Seriously, compared to other APIs, this is not a large change and the benefit is huge. Please do it on ListModel, ComboBoxModel and TreeModel ... that's the really least that can be done on Swing with generics. Swing is clearly not a focused area of the JDK.


Submitted On 05-JUN-2008
Any progress with this?


Submitted On 15-OCT-2008
When are we going to start use generics here? This defect is very old! I hate casting to object :(


Submitted On 25-NOV-2009
Puce
As some of you might already know, some time ago I started the swing-generics project to "generify" the Swing framework.

Now my patch to "generify" JList, along with AbstractListModel, DefaultListCellRenderer, DefaultListModel, ListCellRenderer and ListModel, has been commited to the OpenJDK/ Swing repository!

You can learn more about the patch at the project site:
https://swing-generics.dev.java.net/

or my blog:
http://puces-blog.blogspot.com/2009/11/news-swing-generics-openjdk-jlist-patch.html

If you're interested in the future of Swing and this issue, join the discussions in the OpenJDK Swing mailing list:
http://mail.openjdk.java.net/mailman/listinfo/swing-dev

Related issues:
Sun: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6823603

OpenJDK: https://bugs.openjdk.java.net/show_bug.cgi?id=100029

-Puce



PLEASE NOTE: JDK6 is formerly known as Project Mustang