Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontally flipping a JTree

Tags:

java

swing

jtree

I want to visualize a set of linked objects by focusing on one element and showing all referenced objects and descendants in a tree to the right. That's business as usual.

But if i want to show the referencing objects (i.e. the objects pointing at my selected element) to the left of my selection i'd like to add a little twist. I want it to be a "reverse tree" - a tree with the structure nodes and lines on the right side. That way the selected element (as root node) would be in the middle of the two trees and at least in theory it would be less confusing to the user.

Is there a way to flip the tree structure (not the text of course) horizontally in a JTree?

like image 727
Stroboskop Avatar asked May 19 '26 11:05

Stroboskop


1 Answers

I'm pretty confident that there isn't an easy solution.

Probably the best you can do is, dig into the paint/repaint method of the tree until you find the place where the actual drawing is happening. Then create a tree with your own implementation of that.

Beware that you have to do the same thing for any kind of event handling, in order to find the correct node that was clicked on.

like image 124
Jens Schauder Avatar answered May 22 '26 03:05

Jens Schauder