TOM-12
TOM-12

Reputation: 65

JList like tree

I've got 1 JList using 4 Models. The list shows model depending on which one user chose from JComboBox. What I currently have is that list shows data for all models like this:

group1
group2
group3
...

What I need is that for 3 models it shows like that (above), but for other one it have to show like this (tree structure):

group1
      group1_0
      group1_1
group2
group3
      group3_0
...

Can anyone help me with this? Can anyone point me to some implementation of this or (what else I found is) should I depending on value from JComboBox 'switch' between JList and JTree? And how would I do that without messing with layout (I am using GridBagLayout).

Upvotes: 1

Views: 541

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168845

should I depending on value from JComboBox 'switch' between JList and JTree?

Yes. Unless you can think of a better way.

And how would I do that without messing with layout(I am using GridBagLayout)

Put a panel where the list is now. Give the panel a CardLayout1. Add the JTree and JList to the panel and flip between them as needed.

  1. E.G. as shown in this answer.

Upvotes: 2

Related Questions