Sets the TreeModel that will provide the data. This is a bound property. @param newModel the TreeModel that is to provide the data @beaninfo bound: true description: The TreeModel that will provide the data.
(TreeModel newModel)
| 855 | * description: The TreeModel that will provide the data. |
| 856 | */ |
| 857 | public void setModel(TreeModel newModel) { |
| 858 | clearSelection(); |
| 859 | |
| 860 | TreeModel oldModel = treeModel; |
| 861 | |
| 862 | if(treeModel != null && treeModelListener != null) |
| 863 | treeModel.removeTreeModelListener(treeModelListener); |
| 864 | |
| 865 | if (accessibleContext != null) { |
| 866 | if (treeModel != null) { |
| 867 | treeModel.removeTreeModelListener((TreeModelListener)accessibleContext); |
| 868 | } |
| 869 | if (newModel != null) { |
| 870 | newModel.addTreeModelListener((TreeModelListener)accessibleContext); |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | treeModel = newModel; |
| 875 | clearToggledPaths(); |
| 876 | if(treeModel != null) { |
| 877 | if(treeModelListener == null) |
| 878 | treeModelListener = createTreeModelListener(); |
| 879 | if(treeModelListener != null) |
| 880 | treeModel.addTreeModelListener(treeModelListener); |
| 881 | // Mark the root as expanded, if it isn't a leaf. |
| 882 | Object treeRoot = treeModel.getRoot(); |
| 883 | if(treeRoot != null && |
| 884 | !treeModel.isLeaf(treeRoot)) { |
| 885 | expandedState.put(new TreePath(treeRoot), |
| 886 | Boolean.TRUE); |
| 887 | } |
| 888 | } |
| 889 | firePropertyChange(TREE_MODEL_PROPERTY, oldModel, treeModel); |
| 890 | invalidate(); |
| 891 | } |
| 892 | |
| 893 | /** |
| 894 | * Returns true if the root node of the tree is displayed. |
no test coverage detected