H
helpwithjava
Hello,
I have a JTree application which loads the leaves from a database.
Every time a node is expanded it checks the database and lazily
populates the tree. This works well using a TreeWillExpandListener.
The database can change so when a node is collapsed I want to remove
all the leaves. Then when it is expanded again it will read the
database and show any updates. For the collapse I ahve used a
TreeExpansion listener.
My problem is that when I remove all the leaves from the node on
collapse this node loses the expansion + to the left of it. If I
click where the plus would be then the node does expand and populate
correctly. My problem is the LnF of the node.
My code for collapsing is:
private void removeThisNode(TreePath path) {
TreeNode node = (TreeNode) path.getLastPathComponent();
Enumeration<DefaultMutableTreeNode> children = node.children
();
List<DefaultMutableTreeNode> childrenList = new
ArrayList<DefaultMutableTreeNode>();
while (children.hasMoreElements()) {
DefaultMutableTreeNode object = children.nextElement();
childrenList.add(object);
}
for (MutableTreeNode mutableTreeNode : childrenList) {
defaultTreeModel.removeNodeFromParent(mutableTreeNode);
}
//TODO: why does this get rid of the +
}
I have tried to work out what is causing the + to disappear but cannot
work it out. If I ask the parent node if it is a leaf node it returns
false. So the model knows that leaves can be added to it. It just
loses the +
Thanks for reading and for your "help with java"
I have a JTree application which loads the leaves from a database.
Every time a node is expanded it checks the database and lazily
populates the tree. This works well using a TreeWillExpandListener.
The database can change so when a node is collapsed I want to remove
all the leaves. Then when it is expanded again it will read the
database and show any updates. For the collapse I ahve used a
TreeExpansion listener.
My problem is that when I remove all the leaves from the node on
collapse this node loses the expansion + to the left of it. If I
click where the plus would be then the node does expand and populate
correctly. My problem is the LnF of the node.
My code for collapsing is:
private void removeThisNode(TreePath path) {
TreeNode node = (TreeNode) path.getLastPathComponent();
Enumeration<DefaultMutableTreeNode> children = node.children
();
List<DefaultMutableTreeNode> childrenList = new
ArrayList<DefaultMutableTreeNode>();
while (children.hasMoreElements()) {
DefaultMutableTreeNode object = children.nextElement();
childrenList.add(object);
}
for (MutableTreeNode mutableTreeNode : childrenList) {
defaultTreeModel.removeNodeFromParent(mutableTreeNode);
}
//TODO: why does this get rid of the +
}
I have tried to work out what is causing the + to disappear but cannot
work it out. If I ask the parent node if it is a leaf node it returns
false. So the model knows that leaves can be added to it. It just
loses the +
Thanks for reading and for your "help with java"