java - 如何从java中的JTree中删除每个节点前面的文件夹符号

标签 java swing jtree

我正在尝试从 JTree 的默认节点中删除文件夹符号。 我怎样才能做到这一点?

最佳答案

仅供引用,这里有一个完整的例子:

import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Graphics;
import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.UIManager;

/** @see http://stackoverflow.com/questions/5260223 */
public class JTreeLite {

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            //@Override
            public void run() {
                createGUI();
            }
        });
    }

    private static void createGUI() {
        final JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        Icon empty = new TreeIcon();
        UIManager.put("Tree.closedIcon", empty);
        UIManager.put("Tree.openIcon", empty);
        UIManager.put("Tree.collapsedIcon", empty);
        UIManager.put("Tree.expandedIcon", empty);
        UIManager.put("Tree.leafIcon", empty);

        JTree jt = new JTree();
        frame.add(jt);
        frame.pack();
        frame.setSize(300, 400);
        frame.setVisible(true);
    }
}

class TreeIcon implements Icon {

    private static int SIZE = 0;

    public TreeIcon() {
    }

    public int getIconWidth() {
        return SIZE;
    }

    public int getIconHeight() {
        return SIZE;
    }

    public void paintIcon(Component c, Graphics g, int x, int y) {
        System.out.println(c.getWidth() + " " + c.getHeight() + " " + x + " " + y);
    }
}

关于java - 如何从java中的JTree中删除每个节点前面的文件夹符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5260223/

相关文章:

javafx packager 在 Windows 上一个接一个地安装应用程序

java - JTree 'node title edited' 监听器

java - 如何获取变量的字段名?

java - 在 android 中创建反馈表

java - 如何限制用户只能在文本字段中插入数字?

java - JTree - 向右移动节点

java - 如何为 JTree 中的特定节点调用 DefaultTreeCellRenderer

java - 将元素分隔的文件生成的ArrayList转换为Java中的整数数组

java - Tomcat登录问题

java - 从 JPanel 获取选定的组件