1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
public void paint(Graphics g, JComponent c) {
Font font = c.getFont();
FontMetrics metrics = c.getFontMetrics(font);
Dimension size = c.getSize();
Insets insets = c.getInsets();
float alpha = 0.50f;
Graphics2D g2 = (Graphics2D)g;
try {
Robot robot = new Robot();
BufferedImage img = robot.createScreenCapture(new Rectangle(
insets.left + 1,
insets.top + 1,
size.width - (insets.left + insets.right - 1),
size.height - (insets.top + insets.bottom) - 1));
g2.drawImage(img, size.width - 1, size.height - 1, null);
} catch (AWTException e) {
}
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
if (c.isOpaque()) {
g2.setPaint(c.getBackground());
g2.fillRect(0, 0, size.width, size.height);
}
g2.setColor(c.getForeground());
g2.setFont(font);
// fix for bug 4153892
String tipText = ((JToolTip)c).getTipText();
if (tipText == null) {
tipText = "";
}
Rectangle paintTextR = new Rectangle(
insets.left,
insets.top,
size.width - (insets.left + insets.right),
size.height - (insets.top + insets.bottom));
View v = (View) c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
v.paint(g2, paintTextR);
} else {
g2.drawString(tipText, paintTextR.x + 3, paintTextR.y + metrics.getAscent());
}
} |
Partager