Skip to main content

Replace uses of Enumeration, Vector, etc, in Swing APIs

5 replies [Last post]
rlinwood
Offline
Joined: 2004-10-12
Points: 0

For example, the JList constructor can take a Vector, but not any other type of collection. There are several problems with this, starting with the fact that no one I know uses Vectors anymore. Secondly, JList should not care what data structure is used to hold the elements that it gets. If anything, JList should take a Collection, and iterate over that to get the list elements.

Also, some methods, such as getExpandedDescendants() and getDescendantToggledPaths() in JTree return Enumerations rather than Iterators.

It would be relatively easy to add these, I think. Please consider it. The introduction of Swing coincided with the introduction of the Collection framework, so it is understandable why Swing doesn't make use of them. That said, it's been years, and for those of us who are used to using Collections classes, they're annoyances that harken back to the days of JDK 1.1

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
denismo
Offline
Joined: 2003-06-28
Points: 0

Yep, will make user code much cleaner and safer. AWT also needs to be generified.

Small hint about usage of Vector in some cases: it is RandomAccess. But it is not always the requirement, in some cases it is, indeed, just legacy.

We do consider it for Mustang.

tsinger
Offline
Joined: 2003-06-10
Points: 0

+1, although I think, that first the wholy cow of compatibility needs to be butchered.

zander
Offline
Joined: 2003-06-13
Points: 0

I'm not sure compatibility should have to be a victim here. Lots of methods should be deprecated, yes. But none have to be removed and I personally know of no public/protected fields in Swing that are not List but things like Vector.

tsinger
Offline
Joined: 2003-06-10
Points: 0

I remember a treemodel method which returns an Enumeration.

zander
Offline
Joined: 2003-06-13
Points: 0

I'd like that as well; JList is a good example, yes.
See http://uic.sourceforge.net/api/20/uic/widgets/UICList.html
for 2 methods and the constructors to make obviously clear what I think is needed here. I mean, creating your own open source objects for ONLY this reason should tip the Swing people of, right? :)