Ivan Karlovic
Ivan Karlovic

Reputation: 221

Multi-leveled (nested?) Jlist in Java

Is there a way to create a JList that has more than one (I'm aiming at three) levels?

Something like this:

level 1 item
  level 2 item
  level 2 item
     level 3 item
level 1 item
level 1 item
  level 2 item
  level 2 item
     level 3 item
     level 3 item

I have (up to)three-level-component GUI in my program, and I would need to somehow enable user to organise the elements of the GUI, to move them above or under each other.

Can it be done with JList, or is there another way of dealing with such things? Maybe some library?

Upvotes: 2

Views: 1785

Answers (3)

brimborium
brimborium

Reputation: 9522

I think you should use JTree for that.

Upvotes: 6

Neil
Neil

Reputation: 5780

I think you could, yes, but you're in for a world of hurt that way. JList naturally represents a List from a conceptual point of view, not a tree, meaning most of the ordering logic would have to be done by you. What you're probably interested in is a JTree instead.

Upvotes: 8

km1
km1

Reputation: 2453

You can implement your own ListCellRenderer and your own ListModel.

http://docs.oracle.com/javase/6/docs/api/javax/swing/JList.html

Upvotes: 2

Related Questions