Go Back   Java Programming Forums > Java Standard Edition Programming Help > AWT / Java Swing


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 29-04-2010, 08:27 AM
Junior Member
 

Join Date: Mar 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
ni4ni is on a distinguished road
Default How to show empty directories in JTree ?

Hello

I am trying to use JTree to show a directory tree on my filesystem.
The problem is that some of the directories on the file system are empty. JTree, in its default behavior, assumes that a node that does not have children is a leaf node and changes its icon accordingly.

I want "directory" node to show as directories and only "file" nodes to show as leaf nodes.
How do I change JTree's default behavior ?

Thanks

Guy



Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 30-04-2010, 05:55 AM
Darryl.Burke's Avatar
Member
 

Join Date: Mar 2010
Location: Madgaon, Goa, India
Posts: 198
Thanks: 4
Thanked 14 Times in 14 Posts
Darryl.Burke is on a distinguished road
Default Re: How to show empty directories in JTree ?

I presume you are populating the JTree with File objects. If not, you need to do this first.

Use a custom renderer that sets the icon. You can use either
Java Code
FileSystemView fileSystemView = FileSystemView.getFileSystemView();
setIcont(fileSystemView.getSystemIcon(myFile));
or
Java Code
JFileChooser fileChooser = new JFileChooser();
setIcon(fileChooser.getIcon(myFile));
where myFile is the UserObject of the node, cast to File.

Try one of those and post back if you get stuck anywhere.

db
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
J2ME-Show RMS data in tabular form Sunil Raghuvanshi Mobile Applications 0 22-03-2010 07:17 AM
[SOLVED] Supressing empty lines and does not do until the end! Why ? lumpy What's Wrong With My Code? 1 18-02-2010 11:38 AM
Show Text With cursor ravjot28 AWT / Java Swing 1 20-01-2010 02:02 PM
How do i show all the values in one window(JOptionPane)?? Antonioj1015 AWT / Java Swing 1 26-11-2009 01:24 AM
application Task problem - updating JTree idandush AWT / Java Swing 2 18-06-2009 08:15 AM


100 most searched terms
Search Cloud
2d arraylist java actionlistener actionlistener in java actionlistener java addactionlistener addactionlistener in java addactionlistener java applications of oops could not create java virtual machine xp double format java double to int java double to integer in java double to integer java eclipse shortcut keys eclipse tutorial for beginners exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double java get mouse position java http://www.javaprogrammingforums.com/object-oriented-programming/3713-limiting-decimal-places-double.html java 2d arraylist java actionlistener java addactionlistener java double format java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programmers forum java programming forum java programming forums java programming help java project ideas java sendkeys java two dimensional arraylist java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton actionlistener jtextarea font jtextarea font color jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream two dimensional arraylist java writing ipod apps

All times are GMT. The time now is 11:35 PM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.