java-bootstrap-laf icon indicating copy to clipboard operation
java-bootstrap-laf copied to clipboard

Enable antialias when drawing rounded shapes

Open mgarin opened this issue 12 years ago • 0 comments

I recommend you to enable antialias when drawing non-square shapes to make them smooth and pretty. For example in your JBootstrapButtonUI class:

@Override
public void paint ( Graphics g, JComponent c )
{
    // Enabling antialias
    final Graphics2D g2d = ( Graphics2D ) g;
    final RenderingHints.Key key = RenderingHints.KEY_ANTIALIASING;
    final Object oldAAhint = g2d.getRenderingHint ( key );
    g2d.setRenderingHint ( key, RenderingHints.VALUE_ANTIALIAS_ON );

    // ... painting code ...

    // Restoring previous antialias settings
    g2d.setRenderingHint ( key, oldAAhint );
}

And don't worry, Graphics can be casted to Graphics2D without any issues as it is always passed into paint methods, unless you switch graphics debug on (I doubt you will, because it is a really outdated feature).

You can also look into features provided by Graphics2D class - there are lots of them.

mgarin avatar Oct 15 '13 13:10 mgarin