如何强制一个特定的JTextArea不使用抗锯齿,同时保持其他应用程序的其余部分?

Ste*_*eod 5 java swing

我在Mac OS X 10.6上使用Java 6.我的用户也是如此.我试图强制一个特定的JTextArea不使用抗锯齿.

有任何想法吗?

这是我的测试代码:

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);
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*aux 1

我没有测试它,但你可以尝试重写你的textarea的paintComponent方法:

public void drawComponent(Graphics g)
{
   Graphics2D g2d = (Graphics2D) g;
   g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
   super.drawComponent(g2d);
}
Run Code Online (Sandbox Code Playgroud)