• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

disabling the view of files in Jtree

 
saurabh sood
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i was wondering if it is possible to display only the directories, exculding the files. that is it should look like the folders pane of windows explorer. if so how do we go about it.
thanks
saurabh sood
[ May 28, 2003: Message edited by: saurabh sood ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you asking about JTree or about JFileChooser?

If you are talking about JFileChooser (which I'll assume you mean since you are talking about files, and you'd have to customize JTree to deal with files. ) all you have to do is create a subclass of javax.swing.filechooser.FileFilter that implements the accept() method like this :

then pass this file filter into the setFileFilter() method of the JFileChooser.
 
saurabh sood
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
thanks for replying. my real objective is to create a batch utility, that performs a set of tasks to all the files in that directory. the user selects the directory. i do know how to make only directory visible in JFileChooser.
that can be done by
JFileChooser jfc = new JFileChooser();
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
is it possible to display only directories in JTree
thanks in advance
saurabh sood
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To show directories in a JTree, you would do something like the following:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic