UIDefaults defaults = new UIDefaults();
setRowHeight(getFont().getSize() + 10);
renderer.setBorderSelectionColor(renderer.getBackgroundSelectionColor());
Painter collapsedIconPainter = new Painter() {
@Override
public void paint(Graphics2D g, Object object, int width, int height) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(getForeground());
g.fillPolygon(
new int[]{0, (int) (height * Math.sqrt(0.75)), 0},
new int[]{0, height / 2, height},
3
);
}
};
Painter expandedIconPainter = new Painter() {
@Override
public void paint(Graphics2D g, Object object, int width, int height) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(getForeground());
g.fillPolygon(
new int[]{0, height, height / 2},
new int[]{0, 0, (int) (height * Math.sqrt(0.75))},
3
);
}
};
defaults.put("Tree[Enabled].collapsedIconPainter", collapsedIconPainter);
defaults.put("Tree[Enabled].expandedIconPainter", expandedIconPainter);
defaults.put("Tree:TreeCell[Focused+Selected].backgroundPainter", new SelectionBackgroundPainter(renderer.getBackgroundSelectionColor()));
TreeUI treeUI = getUI();
if (treeUI instanceof MetalTreeUI) {
BasicTreeUI basicUI = (BasicTreeUI) treeUI;
int size = 7;
BufferedImage expandedIcon = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
expandedIconPainter.paint(expandedIcon.createGraphics(), null, size, size);
BufferedImage collapsedIcon = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
collapsedIconPainter.paint(collapsedIcon.createGraphics(), null, size, size);
basicUI.setCollapsedIcon(new ImageIcon(collapsedIcon));
basicUI.setExpandedIcon(new ImageIcon(expandedIcon));
}