Using AWT to paint inside SWT : SWT AWT Swing « SWT « Java Tutorial






Using AWT to paint inside SWT
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;

import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class PaintAWTInsideSWT {

  public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Composite composite = new Composite(shell, SWT.EMBEDDED);

    Frame frame = SWT_AWT.new_Frame(composite);
    Canvas canvas = new Canvas() {
      public void paint(Graphics g) {
        Dimension d = getSize();
        g.drawLine(0, 0, d.width, d.height);
      }
    };
    frame.add(canvas);

    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}








17.118.SWT AWT Swing
17.118.1.Embeded Swing/AWT components to SWTEmbeded Swing/AWT components to SWT
17.118.2.Using AWT to paint inside SWTUsing AWT to paint inside SWT
17.118.3.Embed a JTable in SWT (no flicker)Embed a JTable in SWT (no flicker)
17.118.4.Create a FontData object which encapsulate the essential data to create a swt font.
17.118.5.Create an awt font by converting as much information as possible from the provided swt Font.
17.118.6.Create an awt font by converting as much information as possible from the provided swt FontData.
17.118.7.Creates a swt color instance to match the rgb values of the specified awt color. alpha channel is not supported.
17.118.8.Creates a swt color instance to match the rgb values of the specified awt paint.
17.118.9.Creates an AWT MouseEvent from a swt event.
17.118.10.Creates an awt color instance to match the rgb values of the specified swt color.
17.118.11.Draw Graphics2D stuff on a swt composite
17.118.12.Returns an AWT point with the same coordinates as the specified SWT point.
17.118.13.Returns an SWT point with the same coordinates as the specified AWT point (rounded to integer values).
17.118.14.Returns an SWT point with the same coordinates as the specified AWT point.
17.118.15.Transform a swt Rectangle instance into an AWT Rectangle.
17.118.16.Transform an awt Rectangle2d instance into a swt Rectangle2d.