FlatLaf icon indicating copy to clipboard operation
FlatLaf copied to clipboard

Text Modifies System Font Size Even When Font Size Specified

Open IanKrL opened this issue 1 year ago • 0 comments

Even when I specify a font size via the defaultFont property, the displayed font size is affected by the desktop environment setting for the font (I'll just call it the OS font size for simplicity). The value I set in defaultFont affects it, and the OS font size also affects it.

I'm using Tweaks->Fonts->Interface to set the OS font size. Here are two screenshots taken of the same instance of the simple application I shared below, the only change is in the OS font size but you see the running application font changes size. This would be fine if I hadn't specified a certain font size in code, but I did and so don't expect it to change.

Screenshot from 2024-05-16 12-50-17 Screenshot from 2024-05-16 12-50-05

Test script:

package stuffs;

import java.net.UnknownHostException;
import java.util.Collections;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.FlatLaf;

public class SimpleLaf {
    private static final String DEFAULT_FONT_KEY = "defaultFont";
    private static final String DEFAULT_FONT = "\"Nimbus Roman\" ";
    private static final String TEXT = "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG";
    private static final int FONTSIZE = 11;

    public static void main(String[] args) throws UnknownHostException {
        SwingUtilities.invokeLater(() -> {
            JFrame.setDefaultLookAndFeelDecorated(true);
            FlatLaf.setGlobalExtraDefaults(
                Collections.singletonMap(DEFAULT_FONT_KEY, DEFAULT_FONT + FONTSIZE));
            FlatDarkLaf.setup();
            final JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setTitle("Some Title");
            frame.setSize(350, 100);
            final JPanel panel = new JPanel();
            final JLabel label = new JLabel();
            label.setText(TEXT);
            panel.add(label);
            frame.add(panel);
            frame.setVisible(true);
        });

    }
}

11px in FlatLaf 20px in OS: 11fl_20os 20px in FlatLaf 20px in OS: 20fl_20os 20px in FlatLaf 11px in OS: 20fl_11os 11px in FlatLaf 11px in OS: 11fl_11os

Environment: Flatlaf 3.3 OpenJDK 17.0.8 AlmaLinux 8.9 Gnome 3.32.2

IanKrL avatar May 16 '24 17:05 IanKrL