Skip to main content

Adding entries to tree tree table gives me loads of exceptions...

2 replies [Last post]
bubu1979
Offline
Joined: 2006-03-07
Points: 0

Hi,
I am having a bit of a night mare when I am adding multiple items to the tree table. I keep getting a null pointer execption in the swing swinglabs jar, but I think its because of my own very lazy implenetation

Namely
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at org.jdesktop.swingx.JXTreeTable$TreeTableModelAdapter.nodeForRow(Unknown Source)
at org.jdesktop.swingx.JXTreeTable$TreeTableModelAdapter.getValueAt(Unknown Source)
at org.jdesktop.swingx.JXTable.getValueAt(Unknown Source)
at javax.swing.JTable.prepareRenderer(JTable.java:3902)
at org.jdesktop.swingx.JXTable.prepareRenderer(Unknown Source)
at org.jdesktop.swingx.JXTreeTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:1669)

I think this may be due to my coding, I fairly lazily refresh the whole node every time something is added to it or taken away from it. And The events are fired as I am adding > 1000 entries so the method below are called about the same number of times in quick sucession, perhaps cloging the event que?

It just seems so much work to find out the location of a child on it parent node. Is this lazy coding on my part or am I just doing it wrong?

public void addNode(KeyMutableTreeNode node, int parentKey) {

DefaultMutableTreeNode parent = keyToDefaultMutableTreeNode.get(parentKey);
if(parent == null)
parent = (DefaultMutableTreeNode) model.getRoot();

// I hope the listeners automatically update the tree ???
if(node.getParent() == null || !node.getParent().equals(parent)){
TreeNode oldParent = node.getParent();
parent.add(node);
keyToDefaultMutableTreeNode.put(((ConsolidationTreeObject)node.getUserObject()).getKey(), node);
model.nodeStructureChanged(parent/*, new int[]{(parent.getChildCount() -1 )}*/);
model.nodeStructureChanged(oldParent/*, new int[]{(parent.getChildCount() -1 )}*/);
}
}

public void moveNodesToBeChildren(KeyMutableTreeNode node, int[] childKeys) {
for(int key : childKeys){
DefaultMutableTreeNode child = keyToDefaultMutableTreeNode.get(key);
if(child == null)continue;
// I hope the listeners automatically update the tree ???

DefaultMutableTreeNode parent = (DefaultMutableTreeNode) child.getParent();

if(parent != null && parent == node)continue;

node.add(child);

if(parent != null){
model.nodeStructureChanged(parent);
}
model.nodeStructureChanged(node);
}
expandOut(node);
}

As I said the methods addNode and movenodestobe children are being called in sucession. many many times over. If I am adding a small data set < 100 say I dont get this problem.

Thanks a Million,
Anthony

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Kleopatra

Hi Anthony,

> I am having a bit of a night mare when I am adding multiple items to the tree table. I keep getting a null pointer execption in the swing swinglabs jar, but I think its because of my own very lazy implenetation
>

we have an issue which might be related to the problem you are experiencing:

https://swingx.dev.java.net/issues/show_bug.cgi?id=270

On the other hand, it might be a problem in your model implementation -
can't decide from your code snippet, maybe you could attach a small,
compilable example demonstrating the problem to the above issue?

Thanks
Jeanette

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

bubu1979
Offline
Joined: 2006-03-07
Points: 0

I will try to make a compilable example, that reproduces the bug. Unforunately I have been switched between projects for the next week, but I will try to squeeze this in asap...

All the Best,
Anthony