Package java.awt

Examples of java.awt.FontMetrics.charWidth()


    public void testSetFont() throws Exception {
        Font oldFont = jta.getFont();
        FontMetrics fm = jta.getFontMetrics(oldFont);
        assertEquals(fm.getHeight(), jta.getRowHeight());
        assertEquals(fm.charWidth('m'), jta.getColumnWidth());
        jta.wasCallRevalidate = false;
        Font newFont = new java.awt.Font("SimSun", 0, 12);
        jta.setFont(newFont);
        assertTrue(jta.wasCallRevalidate);
        assertEqualsPropertyChangeEvent("font", oldFont, newFont, listener.event);
View Full Code Here


        jta.setFont(newFont);
        assertTrue(jta.wasCallRevalidate);
        assertEqualsPropertyChangeEvent("font", oldFont, newFont, listener.event);
        fm = jta.getFontMetrics(newFont);
        assertEquals(fm.getHeight(), jta.getRowHeight());
        assertEquals(fm.charWidth('m'), jta.getColumnWidth());
    }

    Dimension getPrefferedSize(final JTextArea jta) {
        Dimension dim1 = jta.getPreferredScrollableViewportSize();
        int width1 = dim1.width;
View Full Code Here

        super.paintComponent(g);
    }

    public void setTabSize(int charactersPerTab) {
        FontMetrics fm = this.getFontMetrics(this.getFont());
        int charWidth = fm.charWidth('w');
        int tabWidth = charWidth * charactersPerTab;

        TabStop[] tabs = new TabStop[36];

        for (int j = 0; j < tabs.length; j++) {
View Full Code Here

    while (i<stop) {
      if (text[i]=='\t')
        x = e.nextTabStop(x, 0);
      else
        x += fm.charWidth(text[i]);
      if (x>endBeforeX) {
        // If not even the first character fits into the space, go
        // ahead and say the first char does fit so we don't go into
        // an infinite loop.
        int intoToken = Math.max(i-textOffset, 1);
View Full Code Here

          }
        }
        int temp = fm.charsWidth(text, start, i-start);
        rect.x = (int)stableX + temp;
        if (text[i]=='\t')
          rect.width = fm.charWidth(' ');
        else
          rect.width = fm.charsWidth(text, start,i-start+1) - temp;
        return rect;
      }
View Full Code Here

          // our drawing a dot for the space.

          // "flushLen+1" ensures text is aligned correctly (or,
          // aligned the same as in getWidth()).
          nextX = x+fm.charsWidth(text, flushIndex,flushLen+1);
          int width = fm.charWidth(' ');

          // Paint background.
          if (bg!=null) {
            paintBackground(x,y, nextX-x,height, g,
                    ascent, host, bg);
View Full Code Here

    // Set up font configuration
    JLabel emptyLabel = new JLabel();
    Font defaultFont = emptyLabel.getFont();
    FontMetrics fm = emptyLabel.getFontMetrics(defaultFont);
    mWidth = fm.charWidth('m');
    headingFont = defaultFont.deriveFont(Font.BOLD);

    // Set up the dialog
    setTitle("City Statistics");
View Full Code Here

    }
    private void checkTextSize(final JTextComponent textComponent,
                              final char ch, final boolean sizeWasSet) {
        final FontMetrics fontMetrics
            = textComponent.getFontMetrics(textComponent.getFont());
        final int charWidth = fontMetrics.charWidth(ch);
        Dimension size = textComponent.getPreferredSize();


        size.width = (sizeWasSet ? 100 : DEFAULT_TEXTFIELD_SIZE) * charWidth;
        if (isHarmony()) {
View Full Code Here

    public void testNextTabStop() {
        Container container = view.getContainer();
        FontMetrics metrics = container.getFontMetrics(container.getFont());
        view.setSize(300, 100);
        float tabPos = view.getTabSize() * metrics.charWidth('m');
        assertEquals(8, view.getTabSize());
        assertEquals(tabPos, view.nextTabStop(0.0f, 0), 0.00001f);
        assertEquals(tabPos, view.nextTabStop(10.0f, 0), 0.00001f);
        assertEquals(tabPos, view.nextTabStop(tabPos - 1, 0), 0.00001f);
        assertEquals(tabPos * 2, view.nextTabStop(tabPos, 0), 0.00001f);
View Full Code Here

    public void testDrawSelectedText() throws BadLocationException {
        textArea.setText("line1\nline2");
        Graphics g = textArea.getGraphics();
        g.setFont(textArea.getFont());
        FontMetrics m = g.getFontMetrics();
        assertEquals(m.charWidth('l'), view.drawSelectedText(g, 0, 0, 0, 1));
        assertEquals(5 + m.charWidth('l'), view.drawSelectedText(g, 5, 0, 0, 1));
        assertEquals(m.stringWidth("line1"), view.drawSelectedText(g, 0, 0, 0, 5));
        assertEquals(m.stringWidth("line1\nli"), view.drawSelectedText(g, 0, 0, 0, 8));
        try {
            view.drawSelectedText(g, 0, 0, -1, 1);
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.