| The Importance of Anti-Aliasing in Java |
If you are developing graphical components in Java and are using the Java 2 platform (jdk1.2 and higher) then you should think about using Anti-Aliasing. I recently wrote a round control-knob for controlling variousparameters of a software synthesizer I am developing. The first version did not use anti-aliasing. It looked like figure 1 to the right. The Knob is useful but not at all nice looking (as you can see) so I added the following code section: // Rendering hint constant private final static RenderingHints AALIAS = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); [...] // The code from the paint method public void paint(Graphics graphics) { if (graphics instanceof Graphics2D) { Graphics2D g2d = (Graphics2D) graphics; g2d.addRenderingHints(AALIAS); } [...]As you can see there is a huge difference in the apperance of the two knobs. The Knob is available for download from here. If you have comments or problems related to this short text pleasemail to Joakim Eriksson | ![]() Figure 1: Knob without anti-aliasing ![]() Figure 2: Knob with anti-aliasing |