Package java.awt

Examples of java.awt.FontMetrics.charWidth()


   
    // get character measurements
    FontMetrics fm = g.getFontMetrics();
    int ascent = fm.getMaxAscent();
    int descent = fm.getMaxDescent();
    int advance = fm.charWidth('W')// width of widest char, more reliable than getMaxAdvance();
    int leading = fm.getLeading();
   
    // calculate size of 10x10 character grid
    int fontHeight = ascent+descent+(leading/2);
    int fontWidth = advance;
View Full Code Here


    }

    public void testSetFont() {
        Font oldFont = jtf.getFont();
        FontMetrics fm = jtf.getFontMetrics(oldFont);
        assertEquals(fm.charWidth('m'), jtf.getColumnWidth());
        jtf.wasCallRevalidate = false;
        Font newFont = new java.awt.Font("SimSun", 0, 12);
        jtf.setFont(newFont);
        assertTrue(jtf.wasCallRevalidate);
        fm = jtf.getFontMetrics(newFont);
View Full Code Here

        jtf.wasCallRevalidate = false;
        Font newFont = new java.awt.Font("SimSun", 0, 12);
        jtf.setFont(newFont);
        assertTrue(jtf.wasCallRevalidate);
        fm = jtf.getFontMetrics(newFont);
        assertEquals(fm.charWidth('m'), jtf.getColumnWidth());
        //checks PropertyCchanegEvent
        PropertyChangeEvent event = listener.event;
        assertEquals("font", event.getPropertyName());
        assertEquals(oldFont, event.getOldValue());
        assertEquals(newFont, event.getNewValue());
View Full Code Here

  private void setTabSize(int tabSize) {
    document.setTabSize(tabSize);

    FontMetrics fm = getFontMetrics(getFont());

    int charWidth = fm.charWidth('#');
    int tabWidth = charWidth * tabSize;

    TabStop[] tabs = new TabStop[100];
    for (int j = 0; j < tabs.length; j++) {
      tabs[j] = new TabStop((j + 1) * tabWidth);
 
View Full Code Here

    int lastCharWidth = -1;

    for (int charCode = 0; charCode < 128; charCode++) {
      if (Character.isValidCodePoint(charCode) && (Character.isLetter(charCode) || Character.isDigit(charCode))) {
        int charWidth = fontMetrics.charWidth((char) charCode);
        if (lastCharWidth >= 0 && charWidth != lastCharWidth) {
          return false; // font is not mono-spaced
        }
        lastCharWidth = charWidth;
      }
View Full Code Here

    }

    private Dimension get_text_preferred_size() {
        Graphics g = GraphicsEnvironment.getLocalGraphicsEnvironment().createGraphics(new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB));
        FontMetrics fm = g.getFontMetrics(getFont());
        System.out.println("[[["+fm.charWidth(0x77) * 81+","+((fm.getHeight() + fm.getLeading()) * 12)+"]]]");
        Dimension size = new Dimension(fm.charWidth(0x77) * 81, (fm.getHeight() + fm.getLeading()) * 12);
        setSize(size);
        return size;
    }

View Full Code Here

    private Dimension get_text_preferred_size() {
        Graphics g = GraphicsEnvironment.getLocalGraphicsEnvironment().createGraphics(new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB));
        FontMetrics fm = g.getFontMetrics(getFont());
        System.out.println("[[["+fm.charWidth(0x77) * 81+","+((fm.getHeight() + fm.getLeading()) * 12)+"]]]");
        Dimension size = new Dimension(fm.charWidth(0x77) * 81, (fm.getHeight() + fm.getLeading()) * 12);
        setSize(size);
        return size;
    }

    /** This method is called from within the constructor to
View Full Code Here

      fCharWidths = new int[len];
      fPosition = new int[len];
      char ch;
      for (int i = 0; i < len; i++) {
        ch = data[i];
        fCharWidths[i] = fm.charWidth(ch);
        if (fCharWidths[i] > fWidth)
          fWidth = fCharWidths[i];
        fCharStrings[i] = new String(data, i, 1);       
        // small kana and punctuation
        if (sDrawsInTopRight.indexOf(ch) >= 0) // if ch is in sDrawsInTopRight
View Full Code Here

     */
    private void evaluate(final Font f) {
        if (f != null) {
            FontMetrics fm = getFontMetrics(f);
            rowHeight = fm.getHeight();
            columnsWidth = fm.charWidth('m');
        } else {
            rowHeight = 0;
            columnsWidth = 0;
        }
    }
View Full Code Here

     */
    private void evaluate(final Font f) {
        if (f != null) {
            FontMetrics fm = getFontMetrics(f);
            rowHeight = fm.getHeight();
            columnsWidth = fm.charWidth('m');
        } else {
            rowHeight = 0;
            columnsWidth = 0;
        }
    }
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.