File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes disabling the view of files in Jtree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "disabling the view of files in Jtree" Watch "disabling the view of files in Jtree" New topic
Author

disabling the view of files in Jtree

saurabh sood
Greenhorn

Joined: Nov 22, 2000
Posts: 17
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

Joined: Oct 18, 2000
Posts: 4121

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.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
saurabh sood
Greenhorn

Joined: Nov 22, 2000
Posts: 17
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

Joined: Oct 18, 2000
Posts: 4121

To show directories in a JTree, you would do something like the following:

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: disabling the view of files in Jtree
 
Similar Threads
PopUp
extract content from table
Method which isn't a constructor should have a return type
java.lang.NoDefFoundError
RequestDispatcher