Java Code Examples for javax.swing.JLabel.paint()

The following are Jave code examples for showing how to use paint() of the javax.swing.JLabel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: bug6302464.java   View Source Code Vote up 7 votes
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;
    }
 
Example 2
Project: incubator-netbeans   File: DefaultOutlineCellRenderer.java   View Source Code Vote up 5 votes
@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);
    }
}
 
Example 3
Project: VASSAL-src   File: Labeler.java   View Source Code Vote up 5 votes
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;
}