Results 1 to 6 of 6

Thread: Java font references using Eclipse

  1. #1

    Default Java font references using Eclipse

    I'm running Eclipse Kepler on openSUSE 12.3 64 bit.
    There seems to be an issue with references to fonts on the system.
    The line

    Code:
    theTitleLabel.setFont(new Font("sansserif",Font.BOLD, 36));
    works correctly, but the more indirect reference

    Code:
    theTitleLabel.setFont(new Font(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()[0], Font.BOLD, 36));
    results in a strange font reproduced. For example, if the title string is "Chess", then what appears in the result is in a Cyrillic font something like "Uxecc", where each character seems to have been pulled from a different character set than I have set on my system.

    So either I need to set an environment var or perhaps there is a font control I need to set before Eclipse/Java can get the correct font?

  2. #2
    Join Date
    Nov 2009
    Location
    West Virginia Sector 13
    Posts
    15,748

    Default Re: Java font references using Eclipse

    What does
    GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()[0]

    actually return?? Maybe it is not what you expect???

  3. #3

    Default Re: Java font references using Eclipse

    Quote Originally Posted by gogalthorp View Post
    What does
    GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()[0]

    actually return?? Maybe it is not what you expect???
    This is correct. The list of family names returned comes back in alphabetic order, and in my case it starts with a couple of math fonts recently downloaded called AMS. Before fetching the AMS fonts, Andale Mono would have been #0, which would have rendered correctly.

  4. #4
    Join Date
    May 2010
    Location
    Space Colony Lagrange Point 22° à, 77° Ƅ, 56° ɤ, 99° ɜ
    Posts
    3,166

    Default Re: Java font references using Eclipse

    colbec wrote:
    >
    > I'm running Eclipse Kepler on openSUSE 12.3 64 bit.
    > There seems to be an issue with references to fonts on the system.
    > The line
    >
    >
    > Code:
    > --------------------
    > theTitleLabel.setFont(new Font("sansserif",Font.BOLD, 36));
    > --------------------
    >
    >
    > works correctly, but the more indirect reference
    >
    >
    > Code:
    > --------------------
    > theTitleLabel.setFont(new Font(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()[0], Font.BOLD, 36));
    > --------------------
    >
    >
    > results in a strange font reproduced. For example, if the title string
    > is "Chess", then what appears in the result is in a Cyrillic font
    > something like "Uxecc", where each character seems to have been pulled
    > from a different character set than I have set on my system.
    >
    > So either I need to set an environment var or perhaps there is a font
    > control I need to set before Eclipse/Java can get the correct font?
    >
    >

    code is working as it should

    in setFont method with three paramaters

    public Font(String name, int style, int size)

    first param is fontname , next is style(italic,bold etc) ,next param is size

    setFont(new Font("sansserif",Font.BOLD, 36));

    The above method always tries to pull in sanserif font family

    setFont(new
    Font(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()[0],
    Font.BOLD, 36));

    This will always pull the first font family available on a local machine

    There is nothing you can do in eclipse

    --
    GNOME 3.6.2
    openSUSE Release 12.3 (Dartmouth) 64-bit
    Kernel Linux 3.7.10-1.16-desktop

  5. #5

    Default Re: Java font references using Eclipse

    Vazhavandan, thanks for this. Just in case I was not clear, gogalthorp was on the right track, I was expecting a different result, hence the surprise when the odd font came up.

    This raises the issue of how to pull a good default font family. In my case pulling the first is not a good idea since it is a specialized font, good only in specific circumstances. I did find a reference to setting a default font such as

    Code:
    super.getFont().getFontName()
    instead of either pulling an index or a specific named font. This approach seems to work well for me at this point.

  6. #6
    Join Date
    May 2010
    Location
    Space Colony Lagrange Point 22° à, 77° Ƅ, 56° ɤ, 99° ɜ
    Posts
    3,166

    Default Re: Java font references using Eclipse

    colbec wrote:
    >
    > Vazhavandan, thanks for this. Just in case I was not clear, gogalthorp
    > was on the right track, I was expecting a different result, hence the
    > surprise when the odd font came up.
    >
    > This raises the issue of how to pull a good default font family. In my
    > case pulling the first is not a good idea since it is a specialized
    > font, good only in specific circumstances. I did find a reference to
    > setting a default font such as
    >
    >
    > Code:
    > --------------------
    > super.getFont().getFontName()
    > --------------------
    >
    >
    > instead of either pulling an index or a specific named font. This
    > approach seems to work well for me at this point.
    >
    >

    you cod snippet pulls the default font set-up on your machine or the
    machine on which the java code runs

    Best approach would be using :-
    ==>Logical fonts as described in this great article here
    http://www.mindprod.com/jgloss/logicalfonts.html
    (or)
    ==> Lucida font packaged inside JREs
    http://www.mindprod.com/jgloss/physicalfonts.html

    --
    GNOME 3.6.2
    openSUSE Release 12.3 (Dartmouth) 64-bit
    Kernel Linux 3.7.10-1.16-desktop

Posting Permissions

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