Search code examples
eclipseswtdraw2d

Turning on anti-aliasing in SWT


I've called gc.setAntialias(SWT.ON); and it does nothing. According to that method, it should work.

The Javadoc states:

Sets the receiver's anti-aliasing value to the parameter, which must be one of SWT.DEFAULT, SWT.OFF or SWT.ON.

It's not working for me, and I'm painting on a simple Canvas.


Solution

  • The following worked for me in an app I built and my guesses at when/how you have to do this.

    So I created a new GC, set the Antialias as you did and then drew what I needed to with that gc object. The key is attaching it to the shell you will draw in.

    GC gc = new GC(shell);
    gc.setAntialias(SWT.ON); 
    //then I attach to LightweightSystem for testing.
    LightweightSystem lws = new LightweightSystem(shell);
    

    Other than that make sure you do this before you draw anything. If you have to call it afterwards maybe try calling a repaint or redraw of the entire space.

    Sorry without more information I am not sure exactly what is wrong.