Package java.awt

Examples of java.awt.FontMetrics.stringWidth()


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


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

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

    // y bottom
    public static void drawStringBottom(Graphics g, String str, int xPos, int yPos)
View Full Code Here

    // y bottom
    public static void drawStringBottom(Graphics g, String str, int xPos, int yPos)
    {
        FontMetrics fm = g.getFontMetrics();
        double strW = fm.stringWidth(str);
        g.drawString(str, xPos + (int)(-strW/2.0 + .5), yPos);
    }
    public static void drawStringLeftBottom(Graphics g, String str, int xPos, int yPos)
    {
        g.drawString(str, xPos, yPos);
View Full Code Here

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

    // y center
    public static void drawStringCenter(Graphics g, String str, int xPos, int yPos)
    {
        FontMetrics fm = g.getFontMetrics();
        double strW = fm.stringWidth(str);
        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();
View Full Code Here

        slider = new JSlider(JSlider.VERTICAL, modelMin, modelMax, modelValue);
        valueLabel = new JLabel() {
            @Override
            public Dimension getPreferredSize() {
                FontMetrics fm = getFontMetrics(getFont());
                return new Dimension(fm.stringWidth("-20.00dB"), fm.getHeight());
            }
        };

        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
View Full Code Here

    final double originX     = shape.getOriginX();
    final double originY     = shape.getOriginY();
    final Color gridLabelsColor = shape.getGridLabelsColour();
    final FontMetrics fontMetrics = FontDesignMetrics.getMetrics(new Font(null, Font.PLAIN, shape.getLabelsSize()));
    final float labelHeight   = fontMetrics.getAscent();
    final float labelWidth     = fontMetrics.stringWidth(String.valueOf((int)maxX));
    final double xorigin = xStep*originX;
    final double yorigin = isXLabelSouth  ? yStep*originY+labelHeight : yStep*originY-2;
    final double width=gridWidth/2.;
    final double tmp = isXLabelSouth ? width : -width;
    final SVGElement texts = new SVGGElement(document);
View Full Code Here

    if(isYLabelWest)
      for(i=tly + (isXLabelSouth ? -width-gridLabelsSize/4. : width+labelHeight), j=maxY ; j>=minY; i+=absStep, j--) {
        label = String.valueOf((int)j);
        text = new SVGTextElement(document);
        text.setAttribute(SVGAttributes.SVG_X, String.valueOf((int)(xorigin-fontMetrics.stringWidth(label)-gridLabelsSize/4.-width)));
        text.setAttribute(SVGAttributes.SVG_Y, String.valueOf((int)i));
        text.setTextContent(label);
        texts.appendChild(text);
      }
    else
View Full Code Here

  protected void paintText(Graphics g, AbstractButton button, Rectangle textRect, String text) {
    Graphics2D g2d = createGraphics(g);
    try {
      g2d.setFont(FONT);
      FontMetrics metrics = g2d.getFontMetrics();
      int width = metrics.stringWidth(text);
      int descent = metrics.getDescent();
      int x = button.getWidth() / 2 - width / 2 + 1;
      int y = button.getHeight() / 2 + descent + 1;
      g2d.setColor(TEXT_LIGHT);
      g2d.drawString(text, ++x, ++y);
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.