Package java.awt

Examples of java.awt.FontMetrics.charWidth()


    private JScrollPane scolls = null;

    private static void setTabs( JTextPane textPane, int charactersPerTab)
  {
    FontMetrics fm = textPane.getFontMetrics( textPane.getFont() );
    int charWidth = fm.charWidth( 'w' );
    int tabWidth = charWidth * charactersPerTab;
    TabStop[] tabs = new TabStop[100];
    for (int j = 0; j < tabs.length; j++)
View Full Code Here


    //  Update sizes when number of digits in the line number changes
    if (lastDigits != digits) {
      lastDigits = digits;
      FontMetrics fontMetrics = getFontMetrics( getFont() );
      int width = fontMetrics.charWidth( '0' ) * digits;
      Insets insets = getInsets();
      int preferredWidth = insets.left + insets.right + width;

      Dimension d = getPreferredSize();
      d.setSize(preferredWidth, HEIGHT);
View Full Code Here

            for (int i = 0; i < captchaCode.length(); i++) {

                // this is a separate canvas used for the character so that
                // we can rotate it independently
                int charWidth = fontMetrics.charWidth(captchaCode.charAt(i));
                int charDim = Math.max(maxAdvance, fontHeight);
                int halfCharDim = (charDim / 2);

                BufferedImage charImage =
                    new BufferedImage(charDim, charDim, BufferedImage.TYPE_INT_ARGB);
View Full Code Here

                          token.offset);
        rect.x = stableX + w;
        end = token.documentToToken(pos);

        if (text[end]=='\t') {
          rect.width = fm.charWidth(' ');
        }
        else {
          rect.width = fm.charWidth(text[end]);
        }
View Full Code Here

        if (text[end]=='\t') {
          rect.width = fm.charWidth(' ');
        }
        else {
          rect.width = fm.charWidth(text[end]);
        }

        return rect;

      }
View Full Code Here

          // our drawing a dot for the space.

          // "flushLen+1" ensures text is aligned correctly (or,
          // aligned the same as in getWidth()).
          nextX = x+fm.charsWidth(text, flushIndex,flushLen+1);
          int width = fm.charWidth(' ');

          // Paint background.
          if (bg!=null) {
            paintBackground(x,y, nextX-x,height, g,
                    ascent, host, bg);
View Full Code Here

            getLineNumberingStartIndex() - 1;
        do {
          lineCount = lineCount/10;
          count++;
        } while (lineCount >= 10);
        cellWidth += fontMetrics.charWidth('9')*(count+1) + 3;
      }
    }

    if (cellWidth!=oldCellWidth) { // Always true
      revalidate();
View Full Code Here

    while (i<stop) {
      if (text[i]=='\t')
        x = e.nextTabStop(x, 0);
      else
        x += fm.charWidth(text[i]);
      if (x>endBeforeX) {
        // If not even the first character fits into the space, go
        // ahead and say the first char does fit so we don't go into
        // an infinite loop.
        int intoToken = Math.max(i-textOffset, 1);
View Full Code Here

    g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, usesFractionalMetrics? RenderingHints.VALUE_FRACTIONALMETRICS_ON : RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
   
    // place the character (on baseline, centered horizontally)
    FontMetrics fm = g.getFontMetrics();
    int cwidth = fm.charWidth(text.charAt(0));
    int height = fm.getHeight();
    int ascent = fm.getAscent();
    int vborder = (int) ((float)(imgSize - height) / 2f);
    int hborder = (int) ((float)(imgSize - cwidth) / 2f);
    g.drawString(text, hborder, vborder+ascent);
View Full Code Here

    // draw the grid of 100 characters
    for (int r=0; r < 10; r++) {
      for (int c=0; c < 10; c++) {
        char ch = (char)(32 + ((r*10)+c));
        g.drawString( String.valueOf(ch), (c*fontSize), (r*fontSize)+ascent);
        charwidths[(r*10)+c] = fm.charWidth(ch);
      }
    }
    g.dispose();
   
    return image;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.