How do you enable anti aliasing in arbitrary Java apps?

后端 未结 4 1178
暗喜
暗喜 2020-11-27 11:32

Many Java Apps don\'t use anti-aliased fonts by default, despite the capability of Swing to provide them. How can you coerce an arbitrary java application to use AA fonts?

4条回答
  •  猫巷女王i
    2020-11-27 11:56

    Swing controls in the latest versions of Java 6 / 7 should automatically abide by system-wide preferences. (If you're using the Windows L&F on a Windows OS then text should render using ClearType if you have that setting enabled system-wide.) So perhaps one solution could simply be: enable the native Look and Feel?

    In applications you're developing, if you render your own text directly, you also need to do something like this (at some point before calling Graphics.drawText or friends):

    if (desktopHints == null) { 
        Toolkit tk = Toolkit.getDefaultToolkit(); 
        desktopHints = (Map) (tk.getDesktopProperty("awt.font.desktophints")); 
    }
    if (desktopHints != null) { 
        g2d.addRenderingHints(desktopHints); 
    } 
    

    Reference: http://weblogs.java.net/blog/chet/archive/2007/01/font_hints_for.html

提交回复
热议问题