简体   繁体   中英

DisplaySingle.setLcdValueFont has no effect in SteelSeries

I am using SteelSeries gauge Java library. In my code DisplaySingle.setLcdValueFont() has no effect: no matter what font I set, the default font is always used. Has anyone managed to make setLcdValueFont work?

Details: I use DisplaySingle in the following way:

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;
    }
}

Later in the code, the display gets added to a JPanel:

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

I had a look at the source of DisplaySingle and noticed that its init() method always resets lcdValueFont to a derivative of LCD_DIGITAL_FONT or LCD_STANDARD_FONT, overwriting value set by a call to .setLcdValueFont. The method init() is called in many places, including various set* methods.

I think there is a bug in DisplaySingle but perhaps I just can't make it work?

This looks like a bug. The font that is set in setLcdValueFont() gets overridden in init() method to default LCD_STANDARD_FONT font. Here is that line:

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

So it is always Verdana 24 . You should be able to change units font, though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM