Package java.awt

Examples of java.awt.FontMetrics


   * @param table
   * @return total width of the table
   */
  private int setColumnSize(JTable table){
    int ret =0;
    FontMetrics fm = table.getFontMetrics(table.getFont());
    for (int i = 0 ; i < table.getColumnCount() ; i++){
      int max = 0;
      for (int j = 0 ; j < table.getRowCount() ; j++){
        String value = (String)table.getValueAt(j,i);
        if (value!=null){
          int taille = fm.stringWidth(value);
          if (taille > max)
            max = taille;
        }
      }
      String nom = (String)table.getColumnModel().getColumn(i).getIdentifier();
      int taille = fm.stringWidth(nom);
      if (taille > max)
        max = taille;
      table.getColumnModel().getColumn(i).setPreferredWidth(max+10);
      ret+=max+10;
    }
View Full Code Here


    }

    private void calculateSize() {
        newMetricsNeeded = false;

        FontMetrics fontMetrics = getFontMetrics(getFont());
        stringAscent = fontMetrics.getAscent();
        stringDescent = fontMetrics.getDescent();
        stringWidth = fontMetrics.stringWidth(message) + shadowX;
        stringHeight = stringAscent + stringDescent + shadowY;

        //  Set initial yoffset
        calculateInitialYOffset();
    }
View Full Code Here

      mygfx.setFont(labelFont);
  // Just in case, requested font unavailable
  else
      mygfx = g;

  FontMetrics fm = mygfx.getFontMetrics();

  int offset = 0;
  double w = (double) size.width;
  double ppu = w / (max - min);
  while (ppu * tickIncrement < 2) {
      tickIncrement += 10;
  }

  int pix_inc = (int)(tickIncrement * ppu);
  int labelSpan = labelIncrement * tickIncrement;

  for (int i = min, x = 0, j = 0;
    i <= max;
    i += tickIncrement, x += pix_inc) {
      if (i % labelSpan == 0) {
     String label = String.valueOf(min + (j * labelSpan));
    offset = 0;
    // Place leftmost label to right
    if (i != min)
        offset = fm.stringWidth(label) / 2;
          if (i >= max// Place rightmost label to left
        offset = fm.stringWidth(label);
   
    mygfx.drawString(label, x - offset, size.height/2);
          mygfx.drawLine(x, size.height/2, x, size.height);
    j++;
      } else
View Full Code Here

    {
      // This was originaly done every time.
      // and the count of instantiated objects was amazing
      _prefSize = new Dimension();
      _prefSize.height = 20;
      FontMetrics fm = getFontMetrics(getFont());
      Calendar cal = Calendar.getInstance();
      cal.set(Calendar.HOUR_OF_DAY, 23);
      cal.set(Calendar.MINUTE, 59);
      cal.set(Calendar.SECOND, 59);
      _prefSize.width = fm.stringWidth(_fmt.format(cal.getTime()));
      Border border = getBorder();
      if (border != null)
      {
        Insets ins = border.getBorderInsets(this);
        if (ins != null)
View Full Code Here

        g.setFont (getFont ());
        Point2D p = t.transform (
          new Point2D.Double (point.getX (), point.getY ()), null);
        g.drawString (text, (int) p.getX (), (int) p.getY ());
       
        FontMetrics fontMetrics = g.getFontMetrics ();
        textWidth = fontMetrics.stringWidth (text);
        textActualHeight = fontMetrics.getAscent () - fontMetrics.getDescent ();
    }
View Full Code Here

    image = new ImageIcon(getClass().getResource("/images/autumn.png"));

    HEIGHT = image.getIconHeight() ;
    WIDTH = image.getIconWidth() ;

    FontMetrics fm = getFontMetrics( font2 ) ;
    TOP = 2*fm.getHeight() ;
    fm = getFontMetrics( font1 ) ;
    BOTTOM = 2*fm.getHeight() ;

    borders = new int[4] ;
    borders[0] = 0 ;
    borders[1] = WIDTH ;
    borders[2] = TOP ;
View Full Code Here

// ----------------------------------------------------------------------------

  // returns
  private int getMiddleX(String text, Font font)
  {
    FontMetrics fm = getFontMetrics(font);
    return ( paintWidth/2 - ((fm.stringWidth(text) + 10) / 2)) ;
  }
View Full Code Here

  {
    TextBlock block = null ;
    AboutTextLine aLine = null ;

    int index = -3 ;
    FontMetrics fm = getFontMetrics(font3);
    try
    {
      InputStream stream = getClass().getResourceAsStream(GUIGlobals.getLocaleHelpPath() + "credits.txt" ) ;
      if (stream == null)
      {
        stream = getClass().getResourceAsStream( GUIGlobals.helpPre +
                                                 "credits.txt" ) ;
      }
      InputStreamReader reader = new InputStreamReader( stream ) ;
      BufferedReader input = new BufferedReader(reader, 1000) ;

      while ( input.ready() )
      {
        String line = input.readLine() ;

        if (line != null)
        {
          line = line.trim() ;

          if (line.length() > 0)
          {
            if (line.charAt(0) == '#'// new Block....
            {
              if (block != null//insert previous block
              {
                textBlocks.add(block) ;
                index+=2 ;
              }

              aLine = new AboutTextLine( line.substring(1).trim()) ;
              aLine.setTag(2);
              aLine.setPos(getMiddleX(aLine.getText(), font2), borders[0] -fm.getHeight()*(index+3)*1.5);
              aLine.setDirection(0.0, 1.0);
              aLine.setFont(font2);

              block = new TextBlock() ;
              block.setHeading(aLine);
              block.setVisible(true);

            }
            else  // Blocklines
            {
              aLine = new AboutTextLine( line.trim() ) ;
              aLine.setPos( getMiddleX( line, font3 ),
                            borders[3] + ( index * fm.getHeight() * 1.5 ) ) ;
              aLine.setTag( 10 ) ;
              aLine.setDirection( 0.0, -1.0 ) ;
              aLine.setFont( font3 ) ;

              block = new TextBlock() ;
View Full Code Here

    else
    if (thread.mode == 1)
    {
      image.paintIcon(this, g, 0, 0);

      FontMetrics fm = g.getFontMetrics( font1 ) ;

      int x1 = ( getWidth() - fm.stringWidth( versionStr ) ) / 2 ;
      int y1 = getHeight() - fm.getHeight() - 4 ;
      int y2 = getHeight() - 5 ;
/*
      int x1 = ( getWidth() - fm.stringWidth( versionStr ) ) / 2 ;
      int y1 = 4 ;
      int y2 = fm.getHeight() +4 ;
*/
      g.setFont( font1 ) ;

      g.setColor( Color.black ) ;
      g.drawString( versionStr, x1, y1 ) ;
      g.drawString( buildStr, x1, y2 ) ;

      g.setFont( font2) ;
      fm = g.getFontMetrics( font2 ) ;
      g.drawString( "JabRef", (getWidth() - fm.stringWidth("JabRef")) /2, fm.getHeight()+10) ;


      for ( TextBlock block : textBlocks){
        if (block.isVisible()) // only if Block is marked as visible
        {
View Full Code Here

        this.getRadius());
    Arc2D arc = new Arc2D.Double(f, this.getAngle(), 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();

    // calculate the bounds of the template value
    FontMetrics fm = g2.getFontMetrics(this.getFont());
    String s = this.getNumberFormat().format(this.getTemplateValue());
    Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm);

    // align this rectangle to the frameAnchor
    Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(
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.