/** * Reloads the model, without changing which nodes are open. nodeStructureChanged, the Swing * method of doing this, doesn't always work. Besides that, nodeStructureChanged closes nodes when * it shouldn't */ public void reloadModel() { Map<ProcessTreeNode, Boolean> isExpanded = new HashMap<ProcessTreeNode, Boolean>(tree.getRowCount()); // save expanded state for (int i = 0; i < tree.getRowCount(); i++) { ProcessTreeNode node = getNodeAtRow(i); if (node != null && !node.isLeaf()) { isExpanded.put(node, Boolean.valueOf(tree.isExpanded(i))); } } m_model.reload(); // restore expanded state for (int i = 0; i < tree.getRowCount(); i++) { ProcessTreeNode node = getNodeAtRow(i); if (node != null && !node.isLeaf()) { // if the node had no expanded state, it will not be expanded boolean expanded = isExpanded.get(node) != null && isExpanded.get(node).booleanValue(); if (expanded) { tree.expandRow(i); } } } invalidate(); requestFocusInWindow(); repaint(); }