Java JTree实现

问题描述 投票:0回答:1

我会简短;我想将JTree的颜色从Metal LF的默认蓝色更改为灰色。我已经看过ExtendedJTreeCellRenderer了。可以使用UIManager完成此操作,如果不需要自定义图标树就可以完成此操作?我有10年以上的Java工作经验,谢谢。

Screenshot

        public static class ExtendedJTreeCellRenderer extends DefaultTreeCellRenderer
        {
            @Override
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row, boolean hasFocus)
            {
                JComponent c = (JComponent) super.getTreeCellRendererComponent(tree, value, isSelected, expanded, leaf, row, hasFocus);

                Graphics graphics = c.getGraphics();

                if(graphics!=null) graphics.setColor(Color.GRAY);

                c.setForeground(new Color(140,140,140));

                c.setBackground(new Color(8,8,8));

                c.setFont(new Font("Georgia", Font.PLAIN, 12));

                c.setOpaque(true);

                //

                this.setClosedIcon(new ImageIcon("images\\folder001.png"));

                //this.setOpenIcon(new ImageIcon(""));

                //this.setLeafIcon(new ImageIcon(""));

                //

                return c;
            }
        }
java swing jtree uimanager
1个回答
0
投票

很抱歉,我们要注意的是:

Screenshot #2

© www.soinside.com 2019 - 2024. All rights reserved.