Package java.awt

Examples of java.awt.FontMetrics.stringWidth()


        // Create header text
        String headerFormat = homePrint.getHeaderFormat();     
        if (headerFormat != null) {
          header = Variable.getMessageFormat(headerFormat).format(variableValues).trim();
          if (header.length() > 0) {
            xHeader = ((float)pageFormat.getWidth() - fontMetrics.stringWidth(header)) / 2;
            yHeader = imageableY + fontMetrics.getAscent();
            imageableY += headerFooterHeight;
            imageableHeight -= headerFooterHeight;
          } else {
            header = null;
View Full Code Here


        // Create footer text
        String footerFormat = homePrint.getFooterFormat();
        if (footerFormat != null) {
          footer = Variable.getMessageFormat(footerFormat).format(variableValues).trim();
          if (footer.length() > 0) {
            xFooter = ((float)pageFormat.getWidth() - fontMetrics.stringWidth(footer)) / 2;
            yFooter = imageableY + imageableHeight - fontMetrics.getDescent();
            imageableHeight -= headerFooterHeight;
          } else {
            footer = null;
          }
View Full Code Here

              g2D.draw(new Line2D.Float(xMax - mainTickSize, y, xMax, y));
              // Draw unit text with a vertical orientation
              g2D.translate(xMax - mainTickSize, y);
              g2D.scale(1 / rulerScale, 1 / rulerScale);
              g2D.rotate(-Math.PI / 2);
              g2D.drawString(yText, -metrics.stringWidth(yText) - 3, fontAscent - 1);
            } else {
              g2D.draw(new Line2D.Float(xMin, y, xMin +  mainTickSize, y));
              // Draw unit text with a vertical orientation
              g2D.translate(xMin + mainTickSize, y);
              g2D.scale(1 / rulerScale, 1 / rulerScale);
View Full Code Here

    String s = obj != null ? obj.toString() : "";
    int w = table.getTableHeader().getColumnModel().getColumn(column).getWidth();

    FontMetrics fm = label.getFontMetrics(label.getFont());
   
    int fmW = fm.stringWidth(s);
   
    // s = w + "/" + fmW + ":" + s;

    int nChars = 3;
    int m = s.length() / 2;
View Full Code Here

      int n1 = nChars / 2;
      int n2 = nChars - n1;
      String left  = s.substring(0, m - n1);
      String right = s.substring(m + n2);
      s2 = left + "..." + right;     
      fmW = fm.stringWidth(s2);
      nChars++;
    }
   
    label.setText(s2);
   
View Full Code Here

      g2d.setPaint(gp);
      g2d.setFont(font);
      final FontMetrics metrics = g2d.getFontMetrics();
      int i = 0;
      for (String s : text) {
        width = metrics.stringWidth(s);
        g2d.drawString(s, this.getWidth() / 2 - width / 2,
            textPos + ((metrics.getHeight() + lineSpacing) * i));
        ++i;
      }
    }
 
View Full Code Here

    final FontMetrics metrics = g2d.getFontMetrics();
    this.lineHeight = metrics.getHeight();
    this.prefferedSize.height = this.lineHeight * 8;
    for (String s : text) {
      prefferedSize.width = Math.max(prefferedSize.width,
          metrics.stringWidth(s));
    }
    this.prefferedSize.width = prefferedSize.width + 6
        * metrics.stringWidth(" ");
  }

View Full Code Here

    for (String s : text) {
      prefferedSize.width = Math.max(prefferedSize.width,
          metrics.stringWidth(s));
    }
    this.prefferedSize.width = prefferedSize.width + 6
        * metrics.stringWidth(" ");
  }

  @Override
  public Dimension getPreferredSize() {
    return this.prefferedSize;
View Full Code Here

        g.drawString(str, xPos + (int)(-strW/2.0 + .5), (int)(yPos + fm.getAscent()*.48 + .5));
    }
    public static void drawStringLeftCenter(Graphics g, String str, int xPos, int yPos)
    {
        FontMetrics fm = g.getFontMetrics();
        double strW = fm.stringWidth(str);
        g.drawString(str, xPos, (int)(yPos + fm.getAscent()*.48 + .5));
    }
    public static void drawStringRightCenter(Graphics g, String str, int xPos, int yPos)
    {
        FontMetrics fm = g.getFontMetrics();
View Full Code Here

        g.drawString(str, xPos, (int)(yPos + fm.getAscent()*.48 + .5));
    }
    public static void drawStringRightCenter(Graphics g, String str, int xPos, int yPos)
    {
        FontMetrics fm = g.getFontMetrics();
        double strW = fm.stringWidth(str);
        g.drawString(str, xPos  - (int)(strW +.5), (int)(yPos + fm.getAscent()*.48 + .5));
    }

    // y top
    public static void drawStringTop(Graphics g, String str, int xPos, int yPos)
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.