how to make JTextPane paint anti-aliased font?

后端 未结 3 849
离开以前
离开以前 2020-12-11 10:22

in the a swing app i\'m rendering text with a custom JComponent, using Graphics.drawString(). here is a sample:
aa text http://img525.imageshac

相关标签:
3条回答
  • 2020-12-11 11:14

    putClientProperty(SwingUtilities2.AA_TEXT_PROPERTY_KEY, null);

    0 讨论(0)
  • 2020-12-11 11:18

    If you want your result to look like the the upper sample, then you want to disable anti-aliasing.

    The first sample in your question has anti-aliasing disabled and the second sample has it 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);
    

    Notice that the reference to com.sun.java.* will make your application non-portable to non-Sun JVMs (and possibly to different versions of Sun JVMs).

    0 讨论(0)
  • 2020-12-11 11:20

    This will result in an antialiased font in a JLabel. Make sure you call super.paintComponent(g); after setting the 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);
                }
            };
    
    0 讨论(0)
提交回复
热议问题