DefaultMutableTreeNode-Text is too long?

前端 未结 2 1796
半阙折子戏
半阙折子戏 2020-12-22 06:55

I have some DefaultMutableTreeNode\'s. While the programm\'s running, I can change the text and revalidate it. But if the text is too long, so for example the text \"tested\

相关标签:
2条回答
  • 2020-12-22 07:42
    • you have to read tutorial about JTree, and examples how to use TreeCellRenderer

    • if you'll real question then please update your question and add there the code in SSCCE form

    0 讨论(0)
  • 2020-12-22 07:44

    the underlying reason is that the layout of the tree nodes is cached and the cache not updated properly. Might f.i. happen if the node is changed under feet of the model, uncomment the nodeChanged to see the difference

        JTree tree = new JTree();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
        int index = 0;
        DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
        String result = "\n";
        Enumeration<?> enumer = root.preorderEnumeration();
        while (enumer.hasMoreElements()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) enumer.nextElement();
            String nodeValue = String.valueOf(node.getUserObject());
            node.setUserObject(nodeValue + ": " + index++);
           //model.nodeChanged(node);
        }
    

    The exact reason in your context might vary, no way to tell without an sscce

    0 讨论(0)
提交回复
热议问题