Package java.awt

Examples of java.awt.FontMetrics


    g.setColor(getBackground());
    g.fillRect(insets.left, insets.top, width, height);
    g.setFont(getFont());
    g.setColor(getForeground());

    FontMetrics metrics = g.getFontMetrics(getFont());

    int xoffset = 0;
    int yoffset = metrics.getHeight();

    StringTokenizer tokenizer = new StringTokenizer(text, " ", true);
    while (tokenizer.hasMoreTokens()) {
      String token = tokenizer.nextToken();
      int tokenWidth = metrics.stringWidth(token);
      if (xoffset + tokenWidth > width) {
        yoffset += metrics.getHeight();
        xoffset = 0;
      }
      g.drawString(token, xoffset + insets.left, yoffset + insets.bottom);
      xoffset += tokenWidth;
    }
View Full Code Here


    //
    // The code below may be weird, but at least it is predictable weird.
    final ExtendedBaselineInfo baselineInfo = renderableText.getBaselineInfo();
    final long baseline = baselineInfo.getBaseline(baselineInfo.getDominantBaseline());

    final FontMetrics fm = g2.getFontMetrics();
    final Rectangle2D rect = fm.getMaxCharBounds(g2);
    final long awtBaseLine = StrictGeomUtility.toInternalValue(-rect.getY());

    final GlyphList gs = renderableText.getGlyphs();
    if (metaData.isFeatureSupported(OutputProcessorFeature.FAST_FONTRENDERING) &&
        isNormalTextSpacing(renderableText))
View Full Code Here

      if (iter.getIndex() == iter.getRunStart())
      {
        if (stringbuffer.length() > 0)
        {
          drawString(stringbuffer.toString(), x, y);
          final FontMetrics fontmetrics = getFontMetrics();
          x = (float) ((double) x + fontmetrics.getStringBounds(stringbuffer.toString(), this).getWidth());
          stringbuffer.delete(0, stringbuffer.length());
        }
        doAttributes(iter);
      }
      stringbuffer.append(c);
View Full Code Here

            int x = point1.x + (symbol_.getIconWidth() / 2);
            int y = point1.y + symbol_.getIconHeight()
                    + echelon_.getIconHeight();
            Font font = new Font("Helvetica", java.awt.Font.PLAIN, 10);
            g.setFont(font);
            FontMetrics fm = g.getFontMetrics();
            int w = fm.stringWidth(eunit.bottom1);
            int h = fm.getHeight();
            total_height += h;
            if (w > total_width)
                total_width = w;
            x -= w / 2;
            y += h;
View Full Code Here

                                                     Font f, String s) {
        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics g = bi.getGraphics();
        g.setFont(f);
        g.setColor(Color.black);
        FontMetrics fm = g.getFontMetrics();

        int stringWidth = fm.stringWidth(s);
        int stringHeight = f.getSize() - 2;
        g.drawString(s, (width - stringWidth) / 2, height - (height - stringHeight) / 2);
        return new ImageIcon(bi);
    }
View Full Code Here

    g.setColor(Color.black);
    Point boxUpperLeft = new Point(60, 60);
    Dimension boxSize  = new Dimension(200, 200);
    Font f = new Font("TimesRoman", Font.PLAIN, 14);
    g.setFont(f);
    FontMetrics fm = g.getFontMetrics(f);
    BoundingBox box = new BoundingBox(boxUpperLeft, boxSize);
    String string = "Hello World! this is a really long string";
    int padding = 10;
    BoundingBox child = null;
    try {
View Full Code Here

               (int)box.getAbsoluteLocation().getY(),
               (int)box.getSize().getWidth(),
               (int)box.getSize().getHeight());
    Font f = new Font("Helvetica", Font.PLAIN, 12);
    g.setFont(f);
    FontMetrics fm = g.getFontMetrics();
    String line1 = "Line 1";
    String line2 = "Line 2";
    String line3 = "Line 3 realllllly loooooong   .h gkjhg kjh gkjh gkjhg kjhg kjhg kjh gk jbhg";
    int padding = 5;
View Full Code Here

    int ty = 170;
   
    for(int i=0;i<modes.length;i++)
      g.drawString(modes[i],100+(50*i),ty-14);
   
    FontMetrics fm = g.getFontMetrics();
    for(int i=0;i<fonts.length;i++)
      g.drawString(fonts[i],98-fm.stringWidth(fonts[i]),ty+(12*i));
   
    Font cf = g.getFont();
   
    for(int i=0;i<fonts.length;i++) {
      for(int j=0;j<modes.length;j++) {
View Full Code Here

      }
      g2.setFont(new Font(fontName, style, fontSize));
    }

    final Font f = g2.getFont();
    final FontMetrics fm = g2.getFontMetrics(f);
    final FontRenderContext frc = g2.getFontRenderContext();
    final double y = area.getCenterY();

    final int highest = getHighest();
    for (int i = getLowest(); i <= highest; i++)
    {
      final double x = valueToJava2D(i, area);
      final String text = String.valueOf(i);

      final float width;
      if (useFontMetricsGetStringBounds)
      {
        final Rectangle2D bounds = fm.getStringBounds(text, g2);
        // getStringBounds() can return incorrect height for some Unicode
        // characters...see bug parade 6183356, let's replace it with
        // something correct
        width = (float) bounds.getWidth();
      }
      else
      {
        width = fm.stringWidth(text);
      }


      final LineMetrics metrics = f.getLineMetrics(text, frc);
      final float descent = metrics.getDescent();
View Full Code Here

            if( m_color!=null )
            {
                g.setColor( m_color );
            }           
           
            FontMetrics fm = g.getFontMetrics();
            int width = fm.stringWidth(m_text) + 20;
            int height = fm.getHeight();
           
            g.drawString(m_text, getWidth() - width, getHeight() - height);
        }
    }
View Full Code Here

TOP

Related Classes of java.awt.FontMetrics

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.