Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text Modifies System Font Size Even When Font Size Specified #843

Open
IanKrL opened this issue May 16, 2024 · 0 comments
Open

Text Modifies System Font Size Even When Font Size Specified #843

IanKrL opened this issue May 16, 2024 · 0 comments

Comments

@IanKrL
Copy link

IanKrL commented May 16, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant