DisplaySingle.setLcdValueFont在SteelSeries中无效

时间:2013-03-07 00:14:36

标签: java swing steelseries

我正在使用SteelSeries规范Java库。在我的代码中DisplaySingle.setLcdValueFont()无效:无论我设置什么字体,都始终使用默认字体。有没有人设法让setLcdValueFont工作?

详细说明: 我以下列方式使用DisplaySingle:

public class ScoreDisplay {
private DisplaySingle display = new DisplaySingle();
    public ScoreDisplay() {
        display.setLcdUnitString("");
        Font font =  new Font("serif", Font.PLAIN,30);
        if (font == null) {
            System.out.println("Font is null");
        }
        System.out.println(font.toString());
        display.setLcdValueFont(font);
        display.setLcdColor(LcdColor.AMBER_LCD);
        display.setLcdValue(99);
        display.setLcdDecimals(0);
        display.setLcdValueFont(font);
    }
    public DisplaySingle getDisplay() {
        return display;
    }
}

稍后在代码中,显示将添加到JPanel:

ScoreDisplay scoreDisplay = new ScoreDisplay();
JPanel panel = new JPanel(new GridLayout(4, 1));
[...]
panel.add(scoreDisplay.getDisplay());

我看了一下DisplaySingle的来源并注意到它的init()方法总是将lcdValueFont重置为LCD_DIGITAL_FONT或LCD_STANDARD_FONT的衍生物,覆盖通过调用.setLcdValueFont设置的值。在许多地方调用方法init(),包括各种set *方法。

我认为DisplaySingle中存在一个错误,但也许我无法让它工作?

1 个答案:

答案 0 :(得分:1)

这看起来像个错误。 setLcdValueFont()方法中设置的字体在init()方法中被覆盖为默认LCD_STANDARD_FONT字体。这是这一行:

lcdValueFont = LCD_STANDARD_FONT.deriveFont(0.625f * getInnerBounds().height);

所以始终是Verdana 24。但是,您应该可以更改单位字体。