This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: disabling the view of files in Jtree
 
Similar Threads
RequestDispatcher
PopUp
java.lang.NoDefFoundError
extract content from table
Method which isn't a constructor should have a return type