我正在尝试从 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/