Package java.awt

Examples of java.awt.FontMetrics


        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();
        double strW = fm.stringWidth(str);
        g.drawString(str, xPos, yPos + fm.getAscent());
    }
View Full Code Here


        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();
        double strW = fm.stringWidth(str);
        g.drawString(str, xPos  - (int)(strW +.5), yPos + fm.getAscent());
    }
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);
    }
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));
    }
View Full Code Here

        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();
        double strW = fm.stringWidth(str);
        g.drawString(str, xPos, (int)(yPos + fm.getAscent()*.48 + .5));
    }
View Full Code Here

        }
    }

    private void drawVerticalLabels(Graphics2D g2) {
        double axisH = yPositionToPixel(originY);
        FontMetrics metrics = g2.getFontMetrics();

        g2.setColor(COLOR_AXIS);

        for (double x = originX + majorX; x < maxX + majorX; x += majorX) {
            int position = (int) xPositionToPixel(x);
            g2.drawString(formatter.format(x), position, (int) axisH + metrics.getHeight());
        }

        for (double x = originX - majorX; x > minX - majorX; x -= majorX) {
            int position = (int) xPositionToPixel(x);
            g2.drawString(formatter.format(x), position, (int) axisH + metrics.getHeight());
        }
    }
View Full Code Here

        g2.setStroke(new BasicStroke(STROKE_AXIS));

        g2.drawLine(0, (int) axisH, getWidth(), (int) axisH);
        g2.drawLine((int) axisV, 0, (int) axisV, getHeight());

        FontMetrics metrics = g2.getFontMetrics();
        g2.drawString(formatter.format(0.0), (int) axisV + 5, (int) axisH + metrics.getHeight());

        g2.setStroke(stroke);
    }
View Full Code Here

    String timeStr = clock.getTimeString();

    Font timeFont = getTimeFont(g);
    g.setFont(timeFont);

    FontMetrics timeFontMetric = g.getFontMetrics();
    Rectangle2D timeStrBounds = timeFontMetric.getStringBounds(timeStr, g);

    int timeStrWidth = (int)timeStrBounds.getWidth();   
    int timeStrHeight = (int)timeStrBounds.getHeight();
    int timeStrX = (winWidth-timeStrWidth)/2;
    int timeStrY = (winHeight+timeStrHeight)/2;
    int timeStrOffset = timeStrHeight/8/2;
    g.drawString(
      timeStr,
      timeStrX,
      timeStrY);

    //// Date String ////

    String dateStr = clock.getDateString();

    Font dateFont = getDateFont(g);
    g.setFont(dateFont);

    FontMetrics dateFontMetric = g.getFontMetrics();
    Rectangle2D dateStrBounds = dateFontMetric.getStringBounds(dateStr, g);

    g.drawString(
      dateStr,
      (winWidth-(int)dateStrBounds.getWidth())/2,
      timeStrY-timeStrHeight-timeStrOffset);
View Full Code Here

                if (elm != null) {
                    int soff = Math.max(elm.getStartOffset(), pos - 1);
                    int eoff = Math.min(pos + 1, elm.getEndOffset());
                    int size = eoff - soff;
                    String str = doc.getText(soff, size);
                    FontMetrics fm = text.getFontMetrics(text.getFont());
                    int h = fm.getHeight();
                    for (int i = 0; i < size; i++) {
                        Rectangle r = text.modelToView(soff + i);
                        r.width = fm.charWidth(str.charAt(i));
                        r.height = h;
                        if (r.contains(point)) {
                            text.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
                            break;
                        }
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.