當前位置: 首頁>>代碼示例>>Java>>正文


Java JLabel.paint方法代碼示例

本文整理匯總了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;
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:bug6302464.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:47,代碼來源:DefaultOutlineCellRenderer.java

示例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;
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:42,代碼來源:Labeler.java


注:本文中的javax.swing.JLabel.paint方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。