[Ldsoss] AntiAlias Java

Jay Askren jay.askren at gmail.com
Fri Aug 25 12:58:41 EDT 2006


I tried your code on version of 1.5_04 of java and it didn't work.
SwingUtilities2 is not mentioned in the javadocs for Java 1.5, so I looked
at the code for SwingUtilities2 source code, and it appears that
SwingUtilities2 is not stable, and the the comments said to not rely on the
class.

I did find the following links:
http://www.javalobby.org/forums/thread.jspa?forumID=61&threadID=14179
http://forum.java.sun.com/thread.jspa?threadID=700404&messageID=4064797


So it looks like at least for now using the RenderingHints might be a bit
more robust though I haven't tried it.  It should work with Java 1.4.


On 8/24/06, Tom Welch <welchtc at ldschurch.org> wrote:
>
>
> Many java applications if using swing tend to have really ugly UI's.  The
> fonts look terrible.  I wrote some code that can make them look a whole lot
> better.  This code requires jre 1.5.  Simply put this method into some
> type of utilities class and then call it whenever you want to make a
> component anti-aliased.  It will find all child components and anti-alias
> them as well.  You typically  just call this method from each form or dialog
> and all components on the form will get fixed.  I've tested this under both
> Windows and Linux and it works well.
>
> *Disclaimer: * I'm not a long time java developer so if you see obvious
> problems or could offer suggestions, please do so.
>
> public static void AntiAliasComponent(JComponent j) {
>         j.putClientProperty(
> com.sun.java.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY,Boolean.TRUE);
>
>         int y = j.getComponentCount();
>         for (int x=0;x<y;x++) {
>             java.awt.Component comp = j.getComponent(x);
>             if (comp instanceof JComponent) {
>                 AntiAliasComponent((JComponent)comp);
>             }
>             // Additional checks for certain types of controls.  These
> require special handling
>             if (comp instanceof JList) {
>                 JList jl = (JList)comp;
>                 DefaultListCellRenderer
> d=(DefaultListCellRenderer)jl.getCellRenderer();
>                 d.putClientProperty(
> com.sun.java.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY,Boolean.TRUE);
>             }
>             else if (comp instanceof JComboBox) {
>                 JComboBox cb = (JComboBox)comp;
>                 BasicComboBoxRenderer
> d=(BasicComboBoxRenderer)cb.getRenderer();
>                 d.putClientProperty(
> com.sun.java.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY, Boolean.TRUE);
>             }
>             else if (comp instanceof JTable) {
>                 JTable tab = (JTable)comp;
>                 DefaultTableCellRenderer d;
>                 d = (DefaultTableCellRenderer)tab.getDefaultRenderer(
> JLabel.class);
>                 d.putClientProperty(
> com.sun.java.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY, Boolean.TRUE);
>
>                 // Do the headers
>                 d =
> (DefaultTableCellRenderer)tab.getTableHeader().getDefaultRenderer();
>                 d.putClientProperty(
> com.sun.java.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY, Boolean.TRUE);
>             }
>         }
>     }
>
> Here is a sibling function to anti-alias the menus of a form.  Simply call
> this for your main menu bar and it will fix all sub-menus.
>
> public static void AntiAliasMenu(JMenuBar j)
>     {
>         int a = j.getMenuCount();
>
>         for (int b=0;b<a;b++) {
>             int x=j.getMenu(b).getItemCount();
>             j.getMenu(b).putClientProperty(
> com.sun.java.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY,Boolean.TRUE);
>
>             for (int y=0;y<x;y++) {
>                 JMenuItem jmi = j.getMenu(b).getItem(y);
>                 if (jmi!=null)
>                     iii.putClientProperty(
> com.sun.java.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY, Boolean.TRUE);
>             }
>         }
>     }
>
> Enjoy.
>
> Tom
>
> --
> Tom Welch
> welchtc at ldschurch.org
> (801) 240-1609
> (858) 829-4614 - Cell
>
> ------------------------------------------------------------------------------
>
> NOTICE: This email message is for the sole use of the
>  intended recipient(s) and may contain confidential and
>  privileged information. Any unauthorized review, use,
>  disclosure or distribution is prohibited. If you are not the
>  intended recipient, please contact the sender by reply email
>  and destroy all copies of the original message.
>
> ------------------------------------------------------------------------------
>
>
>
> _______________________________________________
> Ldsoss mailing list
> Ldsoss at lists.ldsoss.org
> http://lists.ldsoss.org/mailman/listinfo/ldsoss
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ldsoss.org/pipermail/ldsoss/attachments/20060825/58e1233a/attachment.htm


More information about the Ldsoss mailing list