'Error log about wrong font while I create JLabel on Mac
When I create a new JLabel, I get the following error log in the console:
Warning: the fonts "Times" and "Times" are not available for the Java logical font "Serif", which may have unexpected appearance or behavior. Re-enable the "Times" font to remove this warning.
But I do not use this (default) font.
How can I solve this problem or at least suppress the message?
StringBuilder sb = new StringBuilder();
// sb gets some text here
// ...
JLabel label = new JLabel();
label.setFont(new Font("Classic Console Neue", Font.PLAIN, 18)); // changed font to a valid font
label.setText(sb.toString()); // this line will cause the log entry, but why?
A workaround would be to install the Times.ttf on every target computer, but that is not practicable.
Solution 1:[1]
The "Times" font is not installed in macOS 12 Monterey.
Java has been updated to take this into account, newer versions of Java should not print the warning and should correctly use a serif font. See JDK-8273358 for more details.
Solution 2:[2]
For Swing I did not find a way to define another default font, but for components (e.g. JLabel, I found one:
UIManager.put("Label.font", new Font("Courier New", Font.PLAIN, 12));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alexey Ivanov |
| Solution 2 | Christoph Schreiber |
