aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to create JList of JTrees? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to create JList of JTrees?" Watch "How to create JList of JTrees?" New topic
Author

How to create JList of JTrees?

Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello!

I want to have many JTrees displayed one below another vertically.

I decided to use JList as vertical container for JTree.
The problem is after I added JTree to DefaultListModel and created JList with that model
I have toString of JTree displayed as item in JList instead of JTree itself . This is displayed :
javax.swing.JTree[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=16777576,maximumSize=,minimumSize=,preferredSize=,editable=false,invokesStopCellEditing=false,largeModel=false,rootVisible=true,rowHeight=16,scrollsOnExpand=true,showsRootHandles=false,toggleClickCount=2,visibleRowCount=20]

How to tell JList to display JTree component instead of text of JTree.toString method?

Thank you!


True person is moral, false is right!
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

In a nut shell, you need to provide your own renderer which in your case would be a JTree
Recommended reading http://docs.oracle.com/javase/tutorial/uiswing/components/list.html#renderer


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Just remember that items in a JList can't be edited, so you won't be able to interact with JTrees displayed in a JList.

I would use a vertical Box or a JPanel with a GridLayout(0, 1) in a JScrollPane. Either approach might require some fancy handling when tree nodes are expanded or collapsed.


luck, db
There are no new questions, but there may be new answers.
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

@Darryl Burke you are right.

I created simple Renderer as suggested in tutorial and tree does not expand its nodes.

I will try at first vertical Box
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Unfortunately the tree's leaves are not displayed but hidden by background color of whole Box.
I provided image of this.
The root of tree is displayed on white background but text of leaves is hidden by gray background of Box.

How to tell JTree to display itself including text of leaves?
How to add plus icon to collapsed nodes?


[Download JTree.bmp] Download

m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 156
crossposted on SO

edit

- read Oracle tutorial how to use Tree, for working examples

- for better help sooner post an SSCCE, short, runnable, compilable, generated a.m. issue
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

UNFORTUNATELY coderanch does not allow to post image into post
but forces somebody to download it.
This is nearly impossible to believe that somebody will ever download my image.
Without image nothing is clear about problem.
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 156
- notice not attack, nor intention

- not has nothing to do, something with CodeRanch or SO,

- has

1. answers are everywhere based on question

2. empty question equals wider answers, sugestions, guessing

3. question based on image, without an SSCCE is by default hardly answered, event suggestions, guessing on both forums are quite correct, good and clear described

4. goog answers are based on your effort (description, SSCCE, screenshort, asking for potential solutions, common workaround, e.i. bugs)

5. nobody nowhere will be bothering with to simulating of your issue, based only on image



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create JList of JTrees?