Skip to main content

JTreeTable not responding to tree events

5 replies [Last post]
siva
Offline
Joined: 2003-07-15

Hi, I have extended the AbstractTreeTableModel and created my own model. When I run the program I can see the tree. However, when I try to click on any node to expand, nothing happens. I haven't added any listeners myself. I am assuming I don't need to explicitly code for the default expand and collapse functionality (as long as I implement the getChildCount, getChild, isLeaf and a bunch of methods in the TreeTableModel. What am I missing?

thanks
Siva

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
siva
Offline
Joined: 2003-07-15

Hi, thanks for the response. That really helped. I had in my code for the isCellEditable, something like

if(column == 0) return false;

Why is the editable functionality overloaded with tree events? I mean, my requirement is to have a tree whose nodes can't be edited. However, I should be able to perform actions on them like expand, collapse and select. For example, I can't edit the label of a button, but I can click it. Right? So, why should the cell be editable for it to expand or collapse? If that's a limitation I can't overcome, then is there a way to disable the editing of the node name?

rameshgupta
Offline
Joined: 2004-06-04

> Hi, thanks for the response. That really helped. I
> had in my code for the isCellEditable, something
> like
>
> if(column == 0) return false;
>
> Why is the editable functionality overloaded with
> tree events? I mean, my requirement is to have a tree
> whose nodes can't be edited. However, I should be
> able to perform actions on them like expand, collapse
> and select. For example, I can't edit the label of a
> button, but I can click it. Right? So, why should the
> cell be editable for it to expand or collapse? If
> that's a limitation I can't overcome, then is there a
> way to disable the editing of the node name?

Please see the related thread http://www.javadesktop.org/forums/thread.jspa?messageID=22345#22345 for some background on this. This is also filed as JDNC issue #49 (https://jdnc.dev.java.net/issues/show_bug.cgi?id=49).

Basically, JXTreeTable uses a tree internally to manage and render the nodes in the hierarchical column. While the tree itself is not editable, the treetable must allow editing in the hierarchical column in order for mouse clicks to be properly processed.

Now, there are two types of editing that we are talking about:
(1) modifying the expanded/collapsed state of a node, and
(2) modifying the node content/label

In issue 49, I suggested adding a method to explicitly distinguish between the two types of editing. But on closer examination, it seems like there is no need to change the api, just the semantics -- So, nodes should be expanded/collapsed regardless of the return value of isCellEditable(), and the node content/label should be editable iff isCellEditable() returns true.

Thoughts?

Ramesh

siva
Offline
Joined: 2003-07-15

That's fine by me. I can't think of a scenario where one would like to show a node but doesn't want the user to expand/collapse it. Even if there was such a requirement, it may be worked around by making it a leaf-node.

rameshgupta
Offline
Joined: 2004-06-04

> That's fine by me. I can't think of a scenario where
> one would like to show a node but doesn't want the
> user to expand/collapse it. Even if there was such a
> requirement, it may be worked around by making it a
> leaf-node.

Jonathan, Siva,

I fixed this issue, and the files are checked in. Now, AbstractTreeTableModel.isCellEditable() returns false by default, but subclasses may override that to return true, if so desired. You don't have to do anything in isCellEditable() in your case.

The fix did not require any change in the public api.

Ramesh

rameshgupta
Offline
Joined: 2004-06-04

> Hi, I have extended the AbstractTreeTableModel and
> created my own model. When I run the program I can
> see the tree. However, when I try to click on any
> node to expand, nothing happens. I haven't added any
> listeners myself. I am assuming I don't need to
> explicitly code for the default expand and collapse
> functionality (as long as I implement the
> getChildCount, getChild, isLeaf and a bunch of
> methods in the TreeTableModel. What am I missing?
>
> thanks
> Siva

Are you passing your custom TreeTableModel to the constructor for JXTreeTable, or through JXTreeTable.setTreeTableModel()?

A TreeTableModel is fundamentally a TreeModel, in that it does not have any table model functionality. JXTreeTable internally creates a TreeTableModelAdapter that adapts a TreeTableModel (basically a TreeModel) into a TableModel for use with JXTreeTable (basically a JTable).

TreeTableModelAdapter installs the necessary TreeModelListeners and TreeExpansionListeners, so you don't have to. Also, you are correct in assuming that you don't have to explicitly code for the default expand/collapse functionality.

Have you tried putting breakpoints in isCellEditable()? JXTable.isCellEditable() will call TreeTableModelAdapter.isCellEditable(), which, in turn, will call isCellEditable in AbstractTreeTableModel.

All of these methods must return true for node expansion/collapse to work. Please let me know what you find as a result of these breakpoints.

Ramesh