Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / August 2005

Tip: Looking for answers? Try searching our database.

jtree hashtable

Thread view: 
alexandre.melard@gmail.com - 25 Aug 2005 16:40 GMT
Hi,

Do you know if it is possible to get the value of a hash back from a
JTree?

ex:

hash {
 key1 => value1,
 key2 => value2,
 keyn => valuen
}

JTree lJTree = new JTree(hash);

I can get the keys back, but not the values, that would be really
usefull to get them back.

Alex
Thomas Weidenfeller - 26 Aug 2005 08:14 GMT
> hash {
>   key1 => value1,
>   key2 => value2,
>   keyn => valuen
> }

This is a Java, not a Perl group. If you want to write Perl code
consider using perl, not Java.

> JTree lJTree = new JTree(hash);

Use an explicit model. These constructors which take some collection are
just good for cheap hacks. The JTree is supposed to deal with
representation, not with holding data. It converts your hashtable in an
own TreeModel and forgets about the hashtable.

Your values end up in the filed childValue of instances of
javax.swing.JTree.DynamicUtilTreeNode but that field is protected and
you can't access it from the outside. The field is also ignored by the
internally build model, unless it is itself a Vector, Hashtable, or
array (Sun forgot to adapt this code to the new Collection classes a few
years ago - but no one really cares).

> I can get the keys back, but not the values, that would be really
> usefull to get them back.

Use an own model. Using the JTree(Hashtable) constructor is a bad idea.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.