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

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

works correctly, but the more indirect reference

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?

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.

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 :slight_smile:


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

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

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.

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