Skip to main content

JXTreeTable population of model (newbie question)

8 replies [Last post]
akis2
Offline
Joined: 2010-06-18
Points: 0

Hi,

I am new in Swingx and would like to ask the following about JXTreeTable.
1) I have found some examples of JXTreeTable (all fragmented though) and all implement a model for tree table.
Using swing's jtree, a developer can just use the DefaultTreeModel and do not have to implement it's own model.
Is this option available in JXTreeTable as well? Is there an official example? (could not find one)
2) In swing's jtree, the model can be "formatted" via the Netbeans designer, e.g. number/name of columns, number of rows
etc.
I am not able to manipulate the model of the JXTreeTable using the NetBeans form properties. E.g. if I right-click the treetable and click on "Table Contents..." in the customization dialog if I insert a row or column I get an error dialog that says: "Unable to set the model of the table!". Same error if i right click and select properties and try to modify via the Model property. Any info on what am I doing wrong? (bean-info jar is included).

Thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kschaefe
Offline
Joined: 2006-06-08
Points: 0

1) You should review the classes and JavaDoc in the org.jdesktop.swingx.treetable package. We have models with both abstract and "default" implementations.

2) Not exactly sure how that add column stuff works, but it will fail, as you do not define JXTreeTable with a TableModel, but a TreeTableModel, which is adapted for use in JXTable.

Karl

akis2
Offline
Joined: 2010-06-18
Points: 0

Ok,
I did the following:
DefaultMutableTreeTableNode root = new DefaultMutableTreeTableNode("Root");
root.add(new DefaultMutableTreeTableNode("Node"));
List cols = new ArrayList();
cols.add("name");
cols.add("action");
DefaultTreeTableModel m = new DefaultTreeTableModel();//(root);
m.setColumnIdentifiers(cols);
m.setRoot(root);
jXTreeTable1.setTreeTableModel(m);

The result is that I can see the following:
[b]name | action
|
Node[/b]

Why is Root not being displayed? (I used these javadocs http://www.jdocs.com/swingx/1.0/org/jdesktop/swingx/treetable/DefaultTre...)

Thank you

Message was edited by: akis2

Message was edited by: akis2

Message was edited by: akis2

Message was edited by: akis2

kschaefe
Offline
Joined: 2006-06-08
Points: 0

By default JXTreeTable does not show the root node. Set it to be visible:
JXTreeTable.setRootVisible(boolean)

Karl

akis2
Offline
Joined: 2010-06-18
Points: 0

Ok, now is visible.
One last question if possible please.
In my example I have 2 columns in the DefaultTreeTableModel, namely "name" | "action"
My DefaultMutableTreeTableNode though seem to have 1 column. How would I change the code to have displayed

[b]name | action
Root text
|- Leaf text[/b]

I tried
root.setValueAt("Root", 0);
root.setValueAt("Text", 1);

But I get
[b]name | action
Text
|- Leaf [/b]
Is this not possible via DefaultMutableTreeTableNode? How are the other columns supposed to be populated? Is this not possible using default implementation?

Thank you

kschaefe
Offline
Joined: 2006-06-08
Points: 0

Do not use DefaultMutableTreeTableNode. It is for testing only. Use a custom subclass of AbstractMutableTreeTableNode.

Karl

akis2
Offline
Joined: 2010-06-18
Points: 0

I see. Is this the case for DefaultTreeTableModel as well? And custom class of AbstractMutableTreeTableNode only or could I also subclass the DefaultMutableTreeTableNode for a custom node?

Message was edited by: akis2

Message was edited by: akis2

Message was edited by: akis2

kschaefe
Offline
Joined: 2006-06-08
Points: 0

DefaultTreeTableModel is a TreeTableModel that is designed to work with TreeTableNodes. If you are using TreeTableNodes, then you should use this model. Always subclass AbstractMutableTreeTableNode; never subclass DefaultMutableTreeTableNode.

Karl

akis2
Offline
Joined: 2010-06-18
Points: 0

Thank you!