문제

I've managed to get together a functional JTree that loads files and folders out from user.dir, but each node is named with the absolute path, which is kinda bothersome if you don't fancy node names that extends far beyond the borders. So I'm wondering if there is a simple solution to shorten the node names into, say parent directory and file/folder name?

Currently my nodes look like this:

/Users/username/documents/workspace/project/test.txt

What I'm looking for is more the lines of:

/test.txt

If this is something even a beginner should be shamefull for not comprehending, I expect some proverbial spanking. But if this qualifies as a decent question, feel free to twist your noodles. I tried looking into the java look and feel, but that turned out to be a dud.

I'm not sure if I need to write down my code. But if it's of any use, I've used a File array and .list() to get hold of the files, and then inserted 'em into the JTree with 'DefaultMutableTreeNode' and 'DefaultTreeModel'.

도움이 되었습니까?

해결책

Use an appropriate TreeCellRenderer. See File Browser GUI for a great (IMO) example.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top