Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show up an image with swt in java?

Tags:

java

swt

My try as follows,which doesn't come up with anything:

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);

    Image image = new Image(display,
       "D:/topic.png");
    GC gc = new GC(image);
    gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
    gc.drawText("I've been drawn on",0,0,true);
    gc.dispose(); 

    shell.pack();
    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
    // TODO Auto-generated method stub
}
like image 649
lex Avatar asked Dec 15 '10 06:12

lex


People also ask

How do I add a picture to SWT?

Images can be loaded from a known location in the file system using the constructor Image(Display display, String fileLocation): Image image = new Image(display, "C:/eclipse/eclipse/plugins/org. eclipse.

What does SWT mean in Java?

The Standard Widget Toolkit (SWT) is a graphical widget toolkit for use with the Java platform.


1 Answers

See the SWT-Snippets for examples. This one uses an image label

Shell shell = new Shell (display);
Label label = new Label (shell, SWT.BORDER);
label.setImage (image);
like image 149
stacker Avatar answered Oct 24 '22 09:10

stacker