I'm using Java 6 on Mac OS X 10.6. So are my users. I'm trying to force one specific JTextArea not to use anti-aliasing.
Any ideas?
Here's my test code as is:
public static void main(String[] args) {
    JTextArea jTextArea1 = new JTextArea("This is some text which should be anti-aliased");
    jTextArea1.setFont(new Font("Lucida Grande", Font.PLAIN, 14));
    JTextArea jTextArea2 = new JTextArea("Please no anti-aliasing for this text");
    jTextArea2.setFont(new Font("Monaco", Font.PLAIN, 10));
    final JFrame frame = new JFrame();
    frame.getContentPane().add(new JScrollPane(jTextArea1), BorderLayout.NORTH);
    frame.getContentPane().add(new JScrollPane(jTextArea2), BorderLayout.SOUTH);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
In Java > 5, you don't need to override paint methods. You can set a client property like this:
jTextArea2.putClientProperty(sun.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY, null);
Note that SwingUtilities2 is a sun class, so this may not work in other jvms.
I didn't test it, but you can try to override the paintComponent method of your textarea:
public void drawComponent(Graphics g)
{
   Graphics2D g2d = (Graphics2D) g;
   g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
   super.drawComponent(g2d);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With