Forum Stats

  • 3,875,356 Users
  • 2,266,907 Discussions
  • 7,912,175 Comments

Discussions

Needing wisdom re NetBeans Outline ("tree table") component

skiaddict1
skiaddict1 Member Posts: 72
edited Jul 15, 2011 5:44PM in Java Desktop Applications
Greetings all,

I realise I should be posting this on a netbeans forum, and I have already done so, but no-one seems to want to reply over there... :-< So I'm hoping someone here has some relevant experience with this component.

I have two questions:

1. Has anyone managed to get notifications when the user edits a node in the tree part of the treetable? I can get the nodes to be editable, I can type in a change to the text there, but I'm not getting any notification of the change! I have tried registering the Outline model as a TreeModelListener and implementing treeNodesChanged(). I have tried registering the Outline as a TableModelListener and implementing tableChanged(). Nothing is working: I don't get the notifications. Does some kind person have some sample code, or a pointer to some, which would get me going in the right direction? Unless absolutely necessary I would rather not post my code, since it's "complicated"... ;->

2. Can anyone confirm whether this component supports drag 'n' drop? I haven't even started on that journey yet, so knowing "yes" or "no" would be very helpful.

Grateful thanks, as always, for any and all help :->

Answers

  • skiaddict1
    skiaddict1 Member Posts: 72
    edited Jul 15, 2011 5:44PM
    (Responding to my own thread in case the following is of use to someone else someday...)

    Here is how to get this to work:
    private class TreeTable extends Outline implements TableModel
    {
      public void setValueAt(Object aValue, int rowIndex, int columnIndex)
      {
        NodeObjectType node= (NodeObjectType) getPathForRow(rowIndex).getLastPathComponent();
        System.out.println("The user has finished editing the node.");
        System.out.println("Old value: " + node.toString());
        System.out.println("New value: " + aValue);
      }
      public TreePath getPathForRow(int rowInUI)
      {
        int row = convertRowIndexToModel(rowInUI);
        if (getLayoutCache() != null)
        {
          return getLayoutCache().getPathForRow(row);
        }
        else
        {
          return null;
        }
      }
    ...
    }
    where NodeObjectType is the object that you are using for each node of the tree.

    I haven't yet gone into drag 'n' drop, so I can't advise anything on that one. TIA still for tips & pointers with that :->
This discussion has been closed.