-
-
Notifications
You must be signed in to change notification settings - Fork 268
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
Using anti-aliasing for text universally? #218
Comments
Hmm, actually FlatLaf uses anti-aliasing everywhere for painting border, icons, etc. Where exactly do you see non-anti-aliased rendering? |
Sure.
|
Strange... I'll try to reproduce the issue. Could you set a breakpoint at following line and post content of FlatLaf/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java Lines 545 to 558 in 21a12b8
You could also try whether following command line option enables AA for your app: |
BTW does text anti-aliasing work in your app if you use another Laf? E.g. Metal, Nimbus, ... |
I have created this small & simple test program package visuals;
import com.formdev.flatlaf.FlatLightLaf;
import javax.swing.*;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
import java.awt.*;
public class Main {
public static void main(String[] args) throws UnsupportedLookAndFeelException {
// LookAndFeel laf = new NimbusLookAndFeel();
LookAndFeel laf = new FlatLightLaf();
UIManager.setLookAndFeel(laf);
laf.getDefaults().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
JFrame frame = new JFrame("Test Window");
JPanel content = new JPanel(new BorderLayout());
content.add(new JLabel("Hello"), BorderLayout.CENTER);
frame.setContentPane(content);
frame.pack();
frame.setVisible(true);
}
} When I use Flat LaF then anti-aliasing doesn't work. Linux Arch Then I tried putting a breakpoint. Although I am not a UI expert, it seems to me that, when requesting defaults, you always put some defaults there and apply the (non) anti-alias (line 412). So when I later on apply the anti-alias setting, this is never read and of course ignored. |
The problem in the example code is that you invoke Instead simply use So the remaining question is why is anti-aliasing disabled by default on your system? I have some Linux distros here (e.g. Ubuntu and Fedora) where anti-aliasing is enabled by default... |
I can confirm that this works! I am using KDE Plasma, maybe that's why? Anyway I consider the problem solved and sorry for bugging you 😄 |
Helped me too |
@teras and @DanielLyi there is now a fix in main branch that enables text anti-aliasing on Linux even if no Gnome or KDE Desktop properties are available |
@DevCharly import com.formdev.flatlaf.FlatDarculaLaf;
import jiconfont.icons.font_awesome.FontAwesome;
import jiconfont.swing.IconFontSwing;
import javax.swing.*;
import java.awt.*;
public class Main {
public static void main(String[] args) throws UnsupportedLookAndFeelException {
// LookAndFeel laf = new NimbusLookAndFeel();
LookAndFeel laf = new FlatDarculaLaf();
UIManager.setLookAndFeel(laf);
UIManager.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
UIManager.put("useSystemAAFontSettings", "on");
UIManager.put("swing.aatext", "true");
System.setProperty("awt.useSystemAAFontSettings","on");
System.setProperty("swing.aatext", "true");
UIManager.getDefaults().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
IconFontSwing.register(FontAwesome.getIconFont());
JFrame frame = new JFrame("Test Window");
JPanel content = new JPanel(new BorderLayout());
JButton button = new JButton("Hello");
button.setPreferredSize(new Dimension(100, 50));
button.setIcon(IconFontSwing.buildIcon(FontAwesome.ARROW_LEFT, 40));
content.add(button, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(content);
frame.pack();
frame.setVisible(true);
}
} This doesn't seem to work on Windows 10. I am using Jiconfont to create the icons from FontAwesome This is the result I am getting, where the anti aliasing is not working on the icons: Edit: This issue seems to be present regardless of the LookAndFeel, but please help me out, |
@DevCharly I just tested the app on a different OS : Ubuntu , and the antialiasing is actually working. The antialiasing didn't work on Windows, but did work on Ubuntu. I'm starting to think that its probably a problem with how the jdk performs antialiasing based on OS, or maybe how jIconFont performs antialiasing based on OS, or some OS forced featured that controls antialiasing. |
The problem is probably in jiconfont because it first paints the icon character to a bitmap and then paints that bitmap to the screen. If you're using scaling (e.g. 200%) then jiconfont creates a bitmap for unscaled size (e.g. 16x16) and Swing scales the bitmap to 32x32. jiconfont should better draw the icon character directly to the screen. Here is the jiconfont code: There is another similar project called ikonli that you could try: ikonli seems to paint the icon character directly to the screen: |
Yeah, I shifted to ikonli now. It doesn't have this issue |
Based on the comment here #152, I was wondering if there's a global UI parameter to use anti-aliasing everywhere. I have FlatLaf side by side with IntelliJ, and then FlatLaf looks less "modern" because of lack of anti-aliasing.
Should I inherit some UI classes instead? And if yes, again, is it possible to have it somewhere centrally, not for every single instance?
(I know I could fork and do whatever change I like, but I think this might be interesting for other people too, that's why I ask).
The text was updated successfully, but these errors were encountered: