void () { final var showFull = new Ref<>(false); myModel.addTreeModelListener(new TreeModelListener() { @Override public void treeNodesChanged(TreeModelEvent e) { } @Override public void treeNodesInserted(TreeModelEvent e) { onModelUpdate(e); } @Override public void treeNodesRemoved(TreeModelEvent e) { onModelUpdate(e); } @Override public void treeStructureChanged(TreeModelEvent e) { onModelUpdate(e); } private void onModelUpdate(TreeModelEvent e) { final Object root = myModel.getRoot(); if (e.getTreePath().getLastPathComponent() == root) { setUpEmptyText(); final int childCount = myModel.getChildCount(root); final boolean showRoot = childCount > 1 || childCount == 1 && showFull.get(); if (showRoot && !myStateBean.isShowOnlyModified() && !myStateBean.isHideFullyCovered()) { showFull.set(true); } if (showRoot != myTable.getTree().isRootVisible()) { myTable.getTree().setRootVisible(showRoot); } } } }); }