Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to show empty directories in JTree ?

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    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
    FileSystemView fileSystemView = FileSystemView.getFileSystemView();
    setIcont(fileSystemView.getSystemIcon(myFile));
    or
    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

Similar Threads

  1. J2ME-Show RMS data in tabular form
    By Sunil Raghuvanshi in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: January 24th, 2011, 08:06 AM
  2. [SOLVED] Supressing empty lines and does not do until the end! Why ?
    By lumpy in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 18th, 2010, 07:38 AM
  3. Show Text With cursor
    By ravjot28 in forum AWT / Java Swing
    Replies: 1
    Last Post: January 20th, 2010, 10:02 AM
  4. How do i show all the values in one window(JOptionPane)??
    By Antonioj1015 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 25th, 2009, 09:24 PM
  5. application Task problem - updating JTree
    By idandush in forum AWT / Java Swing
    Replies: 2
    Last Post: June 18th, 2009, 03:15 AM