import javax.swing.JLabel; //导入方法依赖的package包/类
@Override
public void paintBorder(Component c, java.awt.Graphics g, int x, int y, int width, int height) {
DefaultOutlineCellRenderer ren = (DefaultOutlineCellRenderer)
((JComponent) c).getClientProperty(DefaultOutlineCellRenderer.class);
if (ren == null) {
ren = (DefaultOutlineCellRenderer) c;
}
if (ren.isShowHandle() && !ren.isLeaf()) {
Icon icon = ren.isExpanded() ? getExpandedIcon() : getCollapsedIcon();
int iconY;
int iconX = ren.getNestingDepth() * getNestingWidth();
if (icon.getIconHeight() < height) {
iconY = (height / 2) - (icon.getIconHeight() / 2);
} else {
iconY = 0;
}
if (isNimbus) {
iconX += icon.getIconWidth()/3; // To look good
}
if (isGtk) {
JLabel lbl = ren.isExpanded () ? lExpandedIcon : lCollapsedIcon;
lbl.setSize (Math.max (getExpansionHandleWidth (), iconX + getExpansionHandleWidth ()), height);
lbl.paint (g);
} else {
icon.paintIcon(c, g, iconX, iconY);
}
}
JCheckBox chBox = ren.getCheckBox();
if (chBox != null) {
int chBoxX = getExpansionHandleWidth() + ren.getNestingDepth() * getNestingWidth();
Rectangle bounds = chBox.getBounds();
int chBoxY;
if (bounds.getHeight() < height) {
chBoxY = (height / 2) - (((int) bounds.getHeight()) / 2);
} else {
if (isNimbus) {
chBoxY = 1;
} else {
chBoxY = 0;
}
}
Dimension chDim = chBox.getSize();
java.awt.Graphics gch = g.create(chBoxX, chBoxY, chDim.width, chDim.height);
chBox.paint(gch);
}
}