Java 我如何强制某个特定的JTextArea不使用抗锯齿,同时在我的应用程序的其余部分保持该功能?

Java 我如何强制某个特定的JTextArea不使用抗锯齿,同时在我的应用程序的其余部分保持该功能?,java,swing,Java,Swing,我在MacOSX10.6上使用Java6。我的用户也是。我试图强制一个特定的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 Gran

我在MacOSX10.6上使用Java6。我的用户也是。我试图强制一个特定的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);
}

我没有测试它,但您可以尝试覆盖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);
}

在Java>5中,您不需要重写
paint
方法。您可以按如下方式设置客户端属性:

jTextArea2.putClientProperty(sun.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY, null);

请注意,
SwingUtilities2
是一个sun类,因此这在其他JVM中可能不起作用。

对不起,我弄错了,这就是我的意思。当然,我们试图关闭抗锯齿功能。我的想法是一样的,但我尝试在
getGraphics()
update()
paint()
paintComponent()
中设置提示,但在这些情况下,没有一个提示得到尊重。