2

I've the following problem.. I've created a JTreeTable and a model which extends AbstractTreeTableModel. The problem is that my data are shown only if I call the fireTreeStructureChanged() method after each inserting operation. In fact if I simple fire the method fireTreeNodesInserted(), nothing happens.

Besides, the data in my row are updated only after an add/remove event, if they simple change their value they are updated only after a click on the table.

How is it possible?

EDIT

When I call fireTreeStructureChanged() then it calls the method fireTableDataChanged(); instead the fireTreeNodesInserted(int firstRow, int lastRow) calls fireTableRowsInserted(); but maybe I pass to it the incorrect parameters...which first and last row I have to pass?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
marco
  • 295
  • 3
  • 13
  • dumb question, but are you sure you're including the correct indices and paths when using the `fireTreeNodesInserted()` method? – sethro Sep 15 '11 at 18:01
  • Right observation...how can I check this?Becasue I'm not sure that I've understood how I have to fill these array...I try with an example: I have a root node R, then I first add a node A, then A1 to A and finally B to R. A very short and simple structure. The root node is inserted when I create the table passing the model. For the adding of the node A to R, I call fireTreeNodesInserted(R, path, index, A); can you explain me the correct parameters?thank you! – marco Sep 16 '11 at 06:17
  • most probably, you do the firing wrong (it's a bit confusing, best explanation is in api doc TreeEvent, from the top of my head) Have a look at DefaultTreeModel for a working example – kleopatra Sep 16 '11 at 07:44

1 Answers1

1

To alleviate the pain of event firing, SwingX has a helper class TreeModelSupport which is usable independent of the project

Edit

that is the standard way :-) A well tested 1:1 mapping of api doc in TreeModelEvent and TreeModelListener, reading it will help you understand.

kleopatra
  • 51,061
  • 28
  • 99
  • 211
  • I also recommend using the SwingX helper class or better, a JXTreeTable instead of the JTreeTable, which is a real pain. – Stephan Oct 16 '11 at 08:05