我正在使用 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 中有一个错误,但也许我无法让它工作?
最佳答案
这看起来像是一个错误。 setLcdValueFont()中设置的字体在 init() 中被覆盖方法默认 LCD_STANDARD_FONT
字体。这是该行:
lcdValueFont = LCD_STANDARD_FONT.deriveFont(0.625f * getInnerBounds().height);
所以它始终是Verdana 24
。不过,您应该能够更改单位字体。
关于java - DisplaySingle.setLcdValueFont 在 SteelSeries 中没有效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15260770/