JTree() components and modifying $$$setupUI$$$

Hi everybody, I just discovered this tool and it's really wonderfull...

Still I'm facing some problems:

1- I want to insert a JTree() component in my GUI. What's strange is that I cannot edit the nodes of my tree, I have tree where the root is called JTree(), with three childs: "color", "sports" and "food", and each one of these nodes contains 4 leafs... I don't understand where it comes from!

2- Although Intellij IDEA says that we should not edit the $$$setupUI$$$ method :), I tried to do it so I can create my JTree() as I want, but when I run it comes back to the automatic generated code, and the changes I've made disapear!

Anybody faced these -or similar- problems!?

Thanks a lot.

2 comments

Hello Lotfi,

L> 1- I want to insert a JTree() component in my GUI. What's strange is
L> that I cannot edit the nodes of my tree, I have tree where the root
L> is called JTree(), with three childs: "color", "sports" and "food",
L> and each one of these nodes contains 4 leafs... I don't understand
L> where it comes from!

This is the default model of the JTree. You need to create your own TreeModel
implementation and assign it to the tree from code.
Here's some documentation for this:
http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html

L> 2- Although Intellij IDEA says that we should not edit the
L> $$$setupUI$$$ method :), I tried to do it so I can create my JTree()
L> as I want, but when I run it comes back to the automatic generated
L> code, and the changes I've made disapear!

IntelliJ IDEA says what it does for a reason. The method is always regenerated
on every compile. You need to place your code in your methods (or in the
class constructor), not in the generated method.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

I agree that you should be able to edit the Tree Model in the UI Designer -- the same way you can edit the the entries in a JList.

The JFormDesigner lets you do that for JTable and JTree. (See attached example of their model editor for JTree).

The JFormDesigner model editor is great for doing quick and dirty mockups.



Attachment(s):
jformdesigner_treemodel.png
0

Please sign in to leave a comment.