Git Product home page Git Product logo

Comments (3)

weisJ avatar weisJ commented on June 3, 2024

Please provide a simple standalone example which demonstrates the issue you are describing.

from darklaf.

tyro668 avatar tyro668 commented on June 3, 2024

Please provide a simple standalone example which demonstrates the issue you are describing.

hello @weisJ ,this is a simple demo code, when open the window and trigger node8,the bug will become!

import com.github.weisj.darklaf.LafManager;
import com.github.weisj.darklaf.theme.IntelliJTheme;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import java.awt.*;

/**
 * @author richie
 * Created by richie on 2023/5/17
 */
public class JTreeDemo {

    public static void main(String... args) {
        LafManager.installTheme(new IntelliJTheme());
        JFrame frame = new JFrame();
        JPanel contentPane = (JPanel) frame.getContentPane();
        contentPane.setLayout(new BorderLayout());

        JTreePane treePane = new JTreePane();
        contentPane.add(treePane, BorderLayout.CENTER);

        frame.setSize(800, 600);
        frame.setVisible(true);
    }

    /**
     * @author richie
     * Created by richie on 2023/5/17
     */
    public static class JTreePane extends JPanel {

        private final DefaultMutableTreeNode root = new DefaultMutableTreeNode();
        private final DefaultTreeModel model = new DefaultTreeModel(root);
        private final JTree jTree = new JTree(model);

        public JTreePane() {
            setLayout(new BorderLayout());
            jTree.setCellRenderer(new DatasourceTreeCellRenderer());
            jTree.setRootVisible(false);

            JScrollPane leftScrollPane = new JScrollPane(jTree);

            add(leftScrollPane, BorderLayout.CENTER);

            DefaultMutableTreeNode node1 = new DefaultMutableTreeNode(new NodeObject("node1"));
            node1.add(new DefaultMutableTreeNode( new NodeObject("node1-1")));
            root.add(node1);
            DefaultMutableTreeNode node2 = new DefaultMutableTreeNode(new NodeObject("node2"));
            root.add(node2);
            DefaultMutableTreeNode node3 = new DefaultMutableTreeNode(new NodeObject("node3"));
            root.add(node3);
            DefaultMutableTreeNode node4 = new DefaultMutableTreeNode(new NodeObject("node4"));
            root.add(node4);
            DefaultMutableTreeNode node5 = new DefaultMutableTreeNode(new NodeObject("node5"));
            root.add(node5);
            DefaultMutableTreeNode node6 = new DefaultMutableTreeNode(new NodeObject("node6"));
            root.add(node6);
            DefaultMutableTreeNode node7 = new DefaultMutableTreeNode(new NodeObject("node7"));
            root.add(node7);
            DefaultMutableTreeNode node8 = new DefaultMutableTreeNode(new NodeObject("node8"));
            node8.add(new DefaultMutableTreeNode( new NodeObject("node8-1")));
            root.add(node8);

            model.reload(root);
        }
    }

    /**
     * @author richie
     * Created by richie on 2023/5/17
     */
    public interface Nameable extends Cloneable {

        String getName();

        void setName(String name);
    }

    /**
     * @author richie
     * Created by richie on 2023/5/17
     */
    public static class NodeObject implements Nameable {

        private String name;

        public NodeObject(String name) {
            this.name = name;
        }

        @Override
        public String getName() {
            return name;
        }

        @Override
        public void setName(String name) {
            this.name = name;
        }
    }

    /**
     * @author richie
     * Created by richie on 2023/5/17
     */
    public static class DatasourceTreeCellRenderer extends DefaultTreeCellRenderer {

        public DatasourceTreeCellRenderer() {

        }

        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
            Object userObject = node.getUserObject();
            if (userObject instanceof Nameable) {
                this.setText(((Nameable) userObject).getName());
            }
            return this;
        }
    }
}

from darklaf.

weisJ avatar weisJ commented on June 3, 2024

I can't reproduce this with the latest snapshot hence will assume it is fixed. I'll release the new version in the next few days. If the issue still happens for you feel free to reopen the issue.

from darklaf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.