本文整理汇总了Java中javax.swing.JLabel.paint方法的典型用法代码示例。如果您正苦于以下问题:Java JLabel.paint方法的具体用法?Java JLabel.paint怎么用?Java JLabel.paint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JLabel
的用法示例。
在下文中一共展示了JLabel.paint方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAntialiasedColors
import javax.swing.JLabel; //导入方法依赖的package包/类
private static HashSet getAntialiasedColors(Object aaHint, int lcdContrast) {
JLabel label = new JLabel("ABCD");
label.setSize(label.getPreferredSize());
label.putClientProperty(KEY_TEXT_ANTIALIASING, aaHint);
label.putClientProperty(KEY_TEXT_LCD_CONTRAST, lcdContrast);
int w = label.getWidth();
int h = label.getHeight();
BufferedImage buffImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImage.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, w, h);
label.paint(g);
g.dispose();
HashSet<Color> colors = new HashSet<>();
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
Color color = new Color(buffImage.getRGB(i, j));
colors.add(color);
}
}
return colors;
}
示例2: paintBorder
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);
}
}
示例3: eval
import javax.swing.JLabel; //导入方法依赖的package包/类
public BufferedImage eval() throws Exception {
// determine whether we are HTML and fix our size
final JLabel label = buildDimensions();
// draw nothing if our size is zero
if (size.width <= 0 || size.height <= 0) return ImageUtils.NULL_IMAGE;
// prepare the target image
final BufferedImage im = ImageUtils.createCompatibleImage(
size.width,
size.height,
bg == null || bg.getTransparency() != Color.OPAQUE
);
final Graphics2D g = im.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// paint the background
if (bg != null) {
g.setColor(bg);
g.fillRect(0, 0, size.width, size.height);
}
// paint the foreground
if (fg != null) {
if (label != null) {
label.paint(g);
}
else {
g.setColor(fg);
g.setFont(font);
final FontMetrics fm = g.getFontMetrics(font);
g.drawString(txt, 0, size.height - fm.getDescent());
}
}
g.dispose();
return im;
}