Mega Code Archive

 
Categories / Java by API / Org Eclipse Swt Graphics
 

DrawText(String string, int x, int y, int flags)

import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class MainClass {   public static void main(String[] a) {     final Display d = new Display();     final Shell shell = new Shell(d);     shell.setSize(250, 200);     shell.setLayout(new FillLayout());     // Create a canvas     Canvas canvas = new Canvas(shell, SWT.NONE);     canvas.addPaintListener(new PaintListener() {       public void paintControl(PaintEvent e) {         // Do some drawing         Rectangle rect = ((Canvas) e.widget).getBounds();         e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_RED));         e.gc.drawFocus(5, 5, rect.width - 10, rect.height - 10);         e.gc.drawText("www.rntsoft.com", 5, 50, SWT.DRAW_MNEMONIC | SWT.DRAW_DELIMITER             | SWT.DRAW_TAB | SWT.DRAW_TRANSPARENT);       }     });                   shell.open();     while (!shell.isDisposed()) {       if (!d.readAndDispatch())         d.sleep();     }     d.dispose();   } }