JTree Directory System

S

seung_shin

From: (e-mail address removed) (seung_shin)
Newsgroups: comp.lang.java.gui
Subject: JTree Directory System
NNTP-Posting-Host: 157.127.124.141
Message-ID: <[email protected]>

I am new to using JTree in JAVA. I implemented my own FileSystemModel
that implements TreeModel. It displays directories only in the file
system. It works fine except I get

C:\Mailbox
C:\Mailbox\Inbox
C:\Mailbox\Sentbox
C:\Mailbox\Savedbox
C:\Mailbox\Savedbox\Notes


How and where do I change it so it will display

Mailbox
Inbox
Sentbox
Savedbox
Notes


Also it displays the tree collapsed when I run it. I can expand the
tree by click on the node but I would like to have an expanded tree as
a default.

Thanks for help in advance~

Seung
 
V

Vincent Cantin

You should make a CellRenderer for your tree, it will display the files in a
differet way.
 
S

seung_shin

Thanks. It worked!!!!

public class FileSystemTreeCellRenderer extends
DefaultTreeCellRenderer {

public Component getTreeCellRendererComponent(JTree tree, Object
value,boolean selected,
boolean expanded,boolean leaf, int row, boolean hasFocus) {

super.getTreeCellRendererComponent(tree, value,
selected,expanded, leaf, row, hasFocus);

String nodeObject;
nodeObject = value.toString();
nodeObject =
nodeObject.substring(nodeObject.lastIndexOf("\\")+1);
setText(nodeObject);

return this;
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

JTree Directory System 2
Jtree renderers 0
Extra Row in JTree 6
[SWING] Problem with JTree 2
Updating JTree When Adding Nodes 2
Programmatically removing nodes from a JTree 2
JTree problem 0
JTable within JTree 1

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top