1

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!

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Sbodd
  • 11,279
  • 6
  • 41
  • 42

3 Answers3

2

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

OscarRyz
  • 196,001
  • 113
  • 385
  • 569
1

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

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Mike
  • 1,481
  • 6
  • 17
  • 22
  • 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 Jun 10 '10 at 18:18
  • :) 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 Jun 10 '10 at 18:38
  • @Support - multilanguage SO: My fault for being too elliptical, Oscar. I meant the traditional approach using `JTree`. – trashgod Jun 10 '10 at 18:41
  • 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 Jun 10 '10 at 18:55
1

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
  • 203,806
  • 29
  • 246
  • 1,045