如何强制一个特定的 JTextArea 不使用抗锯齿,同时在我的应用程序的其余部分保持它? [英] How can I force one specific JTextArea to not use anti-aliasing, while keeping it on for the rest of my app?
本文介绍了如何强制一个特定的 JTextArea 不使用抗锯齿,同时在我的应用程序的其余部分保持它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Mac OS X 10.6 上使用 Java 6.我的用户也是如此.我试图强制一个特定的 JTextArea 不使用抗锯齿.
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.
有什么想法吗?
这是我的测试代码:
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);
}
推荐答案
在 Java > 5 中,您不需要覆盖 paint
方法.您可以像这样设置客户端属性:
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);
请注意,SwingUtilities2
是一个 sun 类,所以这在其他 jvm 中可能不起作用.
Note that SwingUtilities2
is a sun class, so this may not work in other jvms.
这篇关于如何强制一个特定的 JTextArea 不使用抗锯齿,同时在我的应用程序的其余部分保持它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文