开发者

Java Font Display Problem

I realize that, in my certain customer side, when I use the font provided by Graphics2D itself, and decrease the size by 1, it cannot display properly.

private void drawInformationBox(Graphics2D g2, JXLaye开发者_开发问答r<? extends V> layer) {
    if (MainFrame.getInstance().getJStockOptions().getYellowInformationBoxOption() == JStockOptions.YellowInformationBoxOption.Hide) {
        return;
    }

    final Font oldFont = g2.getFont();
    final Font paramFont = new Font(oldFont.getFontName(), oldFont.getStyle(), oldFont.getSize());
    final FontMetrics paramFontMetrics = g2.getFontMetrics(paramFont);
    final Font valueFont = new Font(oldFont.getFontName(), oldFont.getStyle() | Font.BOLD, oldFont.getSize() + 1);
    final FontMetrics valueFontMetrics = g2.getFontMetrics(valueFont);
    /*
     * This date font cannot be displayed properly. Why?
     */
    final Font dateFont = new Font(oldFont.getFontName(), oldFont.getStyle(), oldFont.getSize() - 1);
    final FontMetrics dateFontMetrics = g2.getFontMetrics(dateFont);

Rest of the font is OK. Here is the screen shoot (See the yellow box. There are 3 type of different font within the yellow box) : alt text http://www.investalks.com/attachments/month_1005/10051420318460461ffea5a2f9.jpg


You don't show enough code to determine whether the size is actually the problem...

Having said that, your code will be easier to read if you use the deriveFont() API, as in

final Font dateFont = oldFont.deriveFont((float)(oldFont.getSize() - 1));

This may or may not address your problem. My money is on some locale setting, which is returning characters that have no glyphs in the current font.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜