JButton text smoothing

I use the Awesome Font in JButton to create a clickable icon, however the resulting icon appears with an alias when it is small. Just like a bit of background, Font Awesome is a downloadable ttffile (font file) in which each character is a 'scalable vector icon'. After looking at previous answers to Google and stack overflow, I tried to force a smooth override by overriding the paintComponentJButton method ; this, however, has no effect:

import java.awt.*;
import java.io.File;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;

public class Test extends JFrame{

    public Test(){
        Font fontAwesome = null;
        try {
            fontAwesome = Font.createFont(Font.TRUETYPE_FONT, new File("font-awesome-4.2.0\\fonts\\fontawesome-webfont.ttf"));
            fontAwesome = fontAwesome.deriveFont(Font.PLAIN, 100);
        } catch (FontFormatException | IOException e) {
            e.printStackTrace();
        }

        JButton iconButton = new JButton("\uf0a8"){
            @Override
            public void paintComponent(Graphics g) {
                Graphics2D graphics2d = (Graphics2D) g;
                graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                //graphics2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
                //graphics2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
                //graphics2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
                super.paintComponent(graphics2d);
            }
        };

        iconButton.setFont(fontAwesome);
        iconButton.setFocusPainted(false);

        this.add(iconButton);
        this.setVisible(true);
        this.pack();
    }

    public static void main(String[] args){
        new Test(); 
    }
}

The following images show the received font icons in sizes of 30, 100 and 200 fonts:

enter image description hereenter image description hereenter image description here

How can I force anti-aliasing for small font sizes?

UPDATE: , java-, Font Awesome, .

+4
1

JLabel , Awesome JLabel, JLabel JButton:

    JLabel iconLabel = new JLabel( "\uf0a8" );
    iconLabel.setFont( fontAwesome );

    JButton iconButton = new JButton( );
    iconButton.add( iconLabel );

Linux NimROD L & F. , , YMMV.

+1

All Articles