Figuring Out String Value for Font Constructor

Discussion in 'Java' started by kvnsmnsn@hotmail.com, Feb 15, 2005.

  1. Guest

    I've noticed that when I call "drawString()" without setting the font
    first, the default font prints different widths for different charac-
    ters. So I took a look at the "Font" class to try to figure out how
    to call "setFont" to a font that has an equal width for each character
    it prints. The API shows a contructor for "Font",
    <Font ( String name, int style, int size)>, but you need to know what
    string to put into <name>. Anybody have any idea how to figure out
    the string value I need to put into this constructor to get it to use
    a font that has an equal width for each character in the font? Any
    information on this would be greatly appreciated.

    ---Kevin Simonson

    "You'll never get to heaven, or even to LA,
    if you don't believe there's a way."
    from _Why Not_
     
    , Feb 15, 2005
    #1
    1. Advertising

  2. Dotty Guest

    <> wrote in message
    news:...
    > I've noticed that when I call "drawString()" without setting the font
    > first, the default font prints different widths for different charac-
    > ters. So I took a look at the "Font" class to try to figure out how
    > to call "setFont" to a font that has an equal width for each character
    > it prints. The API shows a contructor for "Font",
    > <Font ( String name, int style, int size)>, but you need to know what
    > string to put into <name>. Anybody have any idea how to figure out
    > the string value I need to put into this constructor to get it to use
    > a font that has an equal width for each character in the font? Any
    > information on this would be greatly appreciated.
    >

    I use this when I want a font where the columns line up.
    "courier" or "Courier New" are also good.

    static final Font treeFont = new Font("SansSerif", Font.PLAIN, 10);
     
    Dotty, Feb 15, 2005
    #2
    1. Advertising

  3. wrote:
    > I've noticed that when I call "drawString()" without setting the font
    > first, the default font prints different widths for different charac-
    > ters. So I took a look at the "Font" class to try to figure out how
    > to call "setFont" to a font that has an equal width for each character
    > it prints. The API shows a contructor for "Font",
    > <Font ( String name, int style, int size)>, but you need to know what
    > string to put into <name>. Anybody have any idea how to figure out
    > the string value I need to put into this constructor to get it to use
    > a font that has an equal width for each character in the font?


    Yes, you read the API documentation of the Font class. Quote:

    > Logical fonts are the five font families defined by the Java platform which must be supported by any Java runtime environment: Serif, SansSerif, Monospaced, Dialog, and DialogInput.


    /Thomas

    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
     
    Thomas Weidenfeller, Feb 15, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. darrel
    Replies:
    19
    Views:
    601
    darrel
    Jan 30, 2006
  2. Dale
    Replies:
    4
    Views:
    368
  3. Flip
    Replies:
    8
    Views:
    678
  4. rboelio
    Replies:
    1
    Views:
    349
    Andrew Thompson
    Feb 3, 2004
  5. mttc
    Replies:
    2
    Views:
    2,415
    Roedy Green
    Jul 3, 2009
Loading...

Share This Page