How to make JTextPane a font smoothing paint?

in a swing application, I present text with a custom JComponent using Graphics.drawString() . here is an example:
aa text http://img525.imageshack.us/img525/4928/drawstringsample.jpg
in the same application, I get text using JTextPane . here is an example:
alt text http://img28.imageshack.us/img28/1134/jtextpanesample.jpg

Can you notice how the bottom sample is a little β€œsmeared”? Well, I can’t figure out how to make it look like a top pattern.

thanks, asaf :-)


update:

  • System.setProperty("awt.useSystemAAFontSettings","false") and "lcd" do not work either.
  • ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF) in paint() does not work
  • putClientProperty( sun.swing.SwingUtilities2 .AA_TEXT_PROPERTY_KEY, Boolean.TRUE) gives java.lang.ClassCastException: java.lang.Boolean cannot be cast to sun.swing.SwingUtilities2$AATextInfo
+2
source share
3 answers

putClientProperty(SwingUtilities2.AA_TEXT_PROPERTY_KEY, null);

+4
source

This will create a smooth font in JLabel. Make sure you call super.paintComponent (g); after installing RenderingHints.

 JLabel lblFont = new JLabel(){ @Override public void paintComponent(Graphics g) { Graphics2D graphics2d = (Graphics2D) g; graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); super.paintComponent(g); } }; 
+6
source

If you want your result to look like a top pattern, you want to turn off anti-aliasing.

In the first example of your question, anti-aliasing is disabled, and the second choice is enabled.

According to http://mindprod.com/jgloss/antialiasing.html the following code should help:

 jtextArea.putClientProperty(com.sun.java.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY, Boolean.TRUE); 

Note that the link to com.sun.java.* Will make your application not portable for non-Sun JVMs (and possibly for different versions of the Sun JVM).

+1
source

Source: https://habr.com/ru/post/953704/


All Articles