Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swing - better font smoothing

Is there any possibility to adjust font smoothing in Java swing application?

Here's some comparison:

enter image description here

The difference isn't huge, but if you look close enough, Adobe Story (and lot of other Flash applications) has stronger and nicer smoothing.

I write text editor in Java, and I would like to achieve such smoothing in my application on JTextPane and JLabels.

like image 394
Rafal Avatar asked Feb 19 '13 18:02

Rafal


1 Answers

Depending on what Object you use to display your Text you need to make a custom one of it and Overwrite the method that is responsible for painting your Text

Here is an example of a custom JTextArea

public class CustomTextArea extends JTextArea {

    @Override
    public void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        super.paint(g);
    }

}

You may need to modify it some more but thats the basic concept

like image 106
Dinh Avatar answered Oct 06 '22 00:10

Dinh