81,092
社区成员
发帖
与我相关
我的任务
分享
public void paint(Graphics2D g) {
Border border = displayStyle.getBorder();
Rectangle b = (border != null)
? deflateRect((Rectangle) getBounds().clone(), border.getInsets()) : getBounds();
Graphics2D gcopy = (Graphics2D) g.create();
Shape save = gcopy.getClip();
gcopy.clip(b);
String text = getText();
if ((text != null) && !text.equals("")) {
TextLine[] lines = getWrappedLines();
if (lines.length > 1) {
int ay = getHorizentalAdvance(lines[lines.length - 1].y);
for (int i = 0; i < lines.length; i++) {
TextLine line = lines[i];
gcopy.drawString(line.text, line.x + b.x, line.y + b.y + ay);
}
} else {
FontMetrics fm = gcopy.getFontMetrics();
Point base = TextView.layoutText(fm.stringWidth(text), fm,
displayStyle.getHorizontalAlignment(), displayStyle.getVerticalAlignment(),
b);
gcopy.drawString(text, base.x, base.y);
}
}
gcopy.setClip(save);
if (getBorder() != null) {
getBorder().paint(gcopy, getBounds());
}
gcopy.dispose();
}