Results 1 to 2 of 2

Thread: Font question

  1. #1
    orchid's Avatar
    orchid is offline Member
    Join Date
    Apr 2007
    Location
    Midwest
    Posts
    60
    Rep Power
    0

    Default Font question

    I have a question regarding font attributes.
    I need to be able to change the width and/or the height of every character I paint on the screen.

    Unfortunately Java only seems to allow to set the size of the font. What I am looking for is the possibility to change either the width, or the height. (this means "taller" characters with same width, or "larger" characters with same height).

    Any idea on how I can do this?
    I'm using this method to paint my characters:

    Java Code:
    Graphics2D g2 = (Graphics2D) g; GlyphVector gv;
    FontRenderContext frc = g2.getFontRenderContext();
    int oneGlyph[] = { asciiToArialSymbol[c] };
    gv = fontSymbol.createGlyphVector( frc, oneGlyph );
    g.setFont(fontSymbol); g.setColor(col);
    g2.drawGlyphVector( gv, hStart+j*hOffset, vStart+(i+1)*vOffset-vDescent);
    thanks

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    If you know the size (width and height) you want for each glyph/letter you can get a pretty good fit by scaling the font with an AffineTransform.
    Java Code:
    AffineTransform at = AffineTransform...
    g2.setFont(font.deriveFont(at));
    g2.draw...

Similar Threads

  1. Replies: 5
    Last Post: 04-25-2009, 09:00 PM
  2. how to set font size for a xml value
    By bala_kj in forum Advanced Java
    Replies: 3
    Last Post: 04-01-2008, 12:00 PM
  3. Swing - Changing component default font
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-11-2008, 11:52 PM
  4. JTable with Font
    By Rama Koti Reddy in forum AWT / Swing
    Replies: 1
    Last Post: 12-12-2007, 06:22 PM
  5. Help with save font information in jtextarea
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 09:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •