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

Icons not getting antialiased / appearing blurry #3

Closed
HiddenMachine3 opened this issue Nov 4, 2022 · 4 comments
Closed

Icons not getting antialiased / appearing blurry #3

HiddenMachine3 opened this issue Nov 4, 2022 · 4 comments

Comments

@HiddenMachine3
Copy link

HiddenMachine3 commented Nov 4, 2022

There appears to be alot of distortion and artifacts when using small icons in JLabels and JButtons.
Here is the code I am using to test this:

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 issue seems to be present regardless of the LookAndFeel.

This is the result I am getting, where the anti aliasing is not working on the icons:
image
image
image

@HiddenMachine3
Copy link
Author

HiddenMachine3 commented Nov 4, 2022

Please tell me a way to work around this. A workaround suggested by someone on stackoverflow , but that just makes it more verbose
Edit: it seems that the above answer also doesn't have antialiasing.
image

I'm beginning to think that it might just have to do with the jdk itself, or the OS I'm using to run this

@HiddenMachine3
Copy link
Author

HiddenMachine3 commented Nov 5, 2022

The problem seems to be deeper than I thought.

I just tested the app on a different OS : Ubuntu , and the antialiasing is actually working.

image

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.

@HiddenMachine3
Copy link
Author

I'm using ikonli now, as this issue is a bummer. Someone pointed out to me that the problem is in jiconfont itself

@caduandrade
Copy link
Contributor

Hi @HiddenMachine3! Sorry, I'm discontinuing this project as there are newer and better ones.
Ikonli is great.

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

2 participants