tags:

views:

47

answers:

3

I need a Swing component that will let me display a tree-structured list of items, and allow the user to select or de-select an arbitrary subset of those items, with the ability to select or deselect an entire subtree's worth of components by picking that subtree's parent. (Basically, something similar to the Eclipse "Export JAR file's" dialog (an image of the relevant dialog is here - I basically want the "Select resources to export" component, but for a Swing application.)

alt text

I know I can do this by creating a custom TreeCellRenderer, a custom TreeCellEditor, and a custom TreeModel - but that seems like an awful lot of work. Are there any good off-the-shelf implementations that I can use?

Thanks!

+1  A: 

Sounds like you are talking about a JTree. It is typically used to display hierarchical data such as a file structure but it can be modified to do other things.

http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html

http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html

Mike
Looks like exhaustion got the best of me and I didn't even see that you had tagged jTree already. As far as I know this is the best way to do it. Sorry for telling you something you already know.
Mike
+1 for tradition; link updated.
trashgod
:) That's not tradition, Google gives you results on 1.4 every time ( because they are more linked I guess ) Replacing `s/1.4.2/6` use to give you 404 but I guess Sun ( sigh , oracle ) notice the trend and now redirects you to the correct one. :... Just... if any one was wondering :P
OscarRyz
@Support - multilanguage SO: My fault for being too elliptical, Oscar. I meant the traditional approach using `JTree`.
trashgod
Oh I see :P I actually didn't really knew why was I writing that comment, until I was about to finish it .. so... I just click on send :P
OscarRyz
+1  A: 

I'd consider NetBeans' Outline. Because it descends from JTable, you can specify multiple selections that include subtrees and leaf nodes.

outline.getSelectionModel().setSelectionMode(
    ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

Addendum: Looking at your picture, you might be able to make use of CheckRenderDataProvider.

trashgod
+1 for an alternative :P
OscarRyz
+2  A: 

You can also take a look at JIDE components to see if they have something like that.

OscarRyz
JIDE Common Layer contains a CheckBoxTree and is open source.
Mark
Bingo - CheckBoxTree is *exactly* what I needed. Thanks!
Sbodd