如何在java中用swt显示图像? [英] How to show up an image with swt in java?

查看:28
本文介绍了如何在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
}

推荐答案

参见 SWT-Snippets 例如.这个使用图像标签

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);

这篇关于如何在java中用swt显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆