Skip to main content

IllegalArgumentException in JXTreeTable

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
15 replies [Last post]
artenum
Offline
Joined: 2007-05-16

Dear all,
I am experiencing some problems with the JXTreeTable.
I have created a JPanel class containing a JXTreeTable and a custom model class extending DefaultTreeTableModel.
When I delete a node in the tree model, the JXTreeTable fires an IllegalArgument exception:
<code>
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: node must be a TreeTableNode managed by this model

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica; color: #de3517}
span.s1 {text-decoration: underline ; color: #1c0391}
span.Apple-tab-span {white-space:pre}

at org.jdesktop.swingx.treetable.DefaultTreeTableModel.isLeaf(DefaultTreeTableModel.java:306)
at javax.swing.plaf.synth.SynthTreeUI.paint(SynthTreeUI.java:288)
at javax.swing.plaf.synth.SynthTreeUI.update(SynthTreeUI.java:226)
at javax.swing.JComponent.paintComponent(JComponent.java:752)
at javax.swing.JComponent.paint(JComponent.java:1029)
at org.jdesktop.swingx.JXTreeTable$TreeTableCellRenderer.paint(JXTreeTable.java:2663)
...
</code>
In my custom model class, here is the code to remove a node:
<code>
public final void removeLayer(final TreeTableNode... layersToRemove) {

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica; min-height: 12.0px}
span.s1 {color: #801a68}

for (final TreeTableNode layer : layersToRemove) {

if (layer != null) {
final TreeTableNode parent = layer.getParent();
final int index = parent.getIndex(layer);
layer.removeFromParent();

notifyLayerRemoved(layer, parent, index);
}
}
</code>

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica; color: #de3517}
span.s1 {text-decoration: underline ; color: #1c0391}
span.Apple-tab-span {white-space:pre}

The notifyLayerRemoved method is the following:
<code>
private void notifyLayerRemoved(final TreeTableNode node, final TreeTableNode parent, final int index) {

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica}
span.s1 {color: #801a68}
span.s2 {color: #2a07c9}

final TreeModelEvent e = new TreeModelEvent(this, new TreePath(getPathToRoot(parent)), new int[] { index }, new Object[] { node });

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica}
span.s1 {color: #801a68}

for (final TreeModelListener l : getTreeModelListeners()) {
l.treeNodesRemoved(e);
}
}
</code>
I seems that the JXTreeTable cell renderer calls the isLeaf() method on the node I just removed. This calls the isValidTreeTableNode(node) method that checks that the node is valid. But it also checks that the parent node is valid. And as I just removed the node from its parent, node.getParent() returns null... Thus the exception.
What did I do wrong?
Thanks for your help
Benoît

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kleopatra
Offline
Joined: 2003-06-11

you might have stumbled onto a swingx bug or done something wrong, code snippets are not enough to decide ;-) Please show a small (!) runnable (!) standalone (!) example that demonstrates the problem.
Cheers
Jeanette

artenum
Offline
Joined: 2007-05-16

kleopatra wrote:

you might have stumbled onto a swingx bug or done something wrong, code snippets are not enough to decide ;-) Please show a small (!) runnable (!) standalone (!) example that demonstrates the problem.
Cheers
Jeanette

Hi Jeanette and thank you for your answer.
Unfortunately, I cannot give you a small runnable standalone example. I just made one but of course I could reproduce the problem. It seems to me it comes from one of the cell renderers. But this is quite hard to debug : the renderer is called whenever I move my mouse on the table (which seems strange by the way) which makes it hard for me to perform my actions as the debugger stops me every time...

kleopatra
Offline
Joined: 2003-06-11

artenum wrote:

Unfortunately, I cannot give you a small runnable standalone example. I just made one but of course I could reproduce the problem.

so what's the problem? Either you show the (short, runnable, standalone!!) example which reproduces the problem or you are on your own ;-)
Cheers
Jeanette
this forum soft is driving me crazy, first it doesn't commit for hours because "subject must not be empty" then it doesn't accept the quote tag ... darrrrn

artenum
Offline
Joined: 2007-05-16

kleopatra wrote:

so what's the problem? Either you show the (short, runnable, standalone!!) example which reproduces the problem or you are on your own ;-)
Cheers
Jeanette
this forum soft is driving me crazy, first it doesn't commit for hours because "subject must not be empty" then it doesn't accept the quote tag ... darrrrn

The problem is that the short example does NOT reproduce the problem :-).
I will have a look at the ordering problem mentioned by another post and will keep you informed. But it's getting late in France and I will certainly post it tomorrow
Kind regards

kleopatra
Offline
Joined: 2003-06-11

artenum wrote:

The problem is that the short example does NOT reproduce the problem :-).

Okay, then your task is to find the difference between your short example and your "real" code :-) And yeah, it's kind of late in Europe, same here in Berlin ..
Cheers
Jeanette
PS: how do you successfully quote? whenever I try, I get the missing-subject error and can't commit. So here we go again with tags showing and not really quoting ...

artenum
Offline
Joined: 2007-05-16

kleopatra wrote:

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}

PS: how do you successfully quote? whenever I try, I get the missing-subject error and can't commit. So here we go again with tags showing and not really quoting ...

To quote, I use the "quote" button. Then I have the missing subject error, copy my text, click the reply button and paste my text (when it works)... Not very user friendly...

... and sometimes, it adds strange css code

kschaefe
Offline
Joined: 2006-06-08

I would guess that you have an ordering problem in the remove. I see you are performing the notification, does one of those force a repaint before the node is completely removed?

kleopatra
Offline
Joined: 2003-06-11

kschaefe wrote:

I would guess that you have an ordering problem in the remove. I see you are performing the notification, does one of those force a repaint before the node is completely removed?

Hmm .. not necessarily, core tree ui doesn't behave correctly always. On second thought to OP: try to use your model on a core tree and see if the problem shows then.
Cheers
Jeanette

artenum
Offline
Joined: 2007-05-16

kleopatra wrote:

Hmm .. not necessarily, core tree ui doesn't behave correctly always. On second thought to OP: try to use your model on a core tree and see if the problem shows then.
Cheers
Jeanette

A few questions:
- what do you mean by OP?
- what do you mean by core tree? a JTree ?
I am trying to understand the problem a little further and will try to reproduce it in a sample code.
In fact, when the treeNodeRemoved(e) method is called on the JXTreeTable, it calls the delayedFireTableDataChanged(e) method of the TreeTableModelAdapter.
In this method, it checks whether the parent node of the removed node is expanded or not... And here it makes a mistake: while the parent node IS expanded, the method returns false. Then a fireTableRowsUpdated(row, row) method is called instead of fireTableRowsDeleted(min, max). The node is thus NOT removed from the JXTreeTable. When the mouse comes over it, the a repaint is called that tries to paint a node that is not anymore in the model... which crashes.
Kind regards

artenum
Offline
Joined: 2007-05-16

Fyi, I tried my code with a JTree and got the same error message than with the JXTreeTable...

kleopatra
Offline
Joined: 2003-06-11

okay, then we are off the hook - it's a core problem, which allows us to point fingers to the core swing team <g>
Still, we might help if we would see the example. Without, I'm out off here
CU
Jeanette
PS: OP = Original Poster (that is you)

artenum
Offline
Joined: 2007-05-16

I found the solution!
As often, the problem was between the keyboard and the chair.
In fact I had overridden the getPathToRoot() method and it failed to return the correct path, which is why my node was not completely removed from the tree.
It works like a charm now.
Thank you for your feedbacks
Benoît

artenum
Offline
Joined: 2007-05-16

The order in which the listeners are called is the following:
- org.jdesktop.swingx.JXTreeTable$TreeTableModelAdapter
- javax.swing.plaf.basic.BasicTreeUI$Handler
- org.jdesktop.swingx.JXTree$XTreeModelHandler
The problem is that after that, the JXTreeTable is displayed as before I deleted the node. When I move the mouse over (which requests a repaint of the cells) the exception is launched. If I do not move the mouse over, there is no error message (but the JXTreeTable is not updated).

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica}

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica}

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica}

kschaefe
Offline
Joined: 2006-06-08

If you can't make a small test case, then please supply the entire model. Something is untoward, but I can't tell what.
Karl

kleopatra
Offline
Joined: 2003-06-11

Karl,

kschaefe wrote:

If you can't make a small test case, then please supply the entire model. Something is untoward, but I can't tell what.

Having the model, everybody (including the OP) can do a small test case ;-) Problem might be the code which is not in the model. I would suggest to stop guessing, it's likely a waste of time.
Cheers
Jeanette