SWT 自定义鼠标图像。

来源:互联网 发布:类似快聊软件 编辑:程序博客网 时间:2024/05/29 11:00

目的:使用指定图像作为鼠标的显示样式。


参考代码:

import org.eclipse.swt.graphics.Cursor;import org.eclipse.swt.graphics.Image;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;public class CursorImageCreate {  public static void main(String[] args) {    final Display display = new Display();    final Shell shell = new Shell(display);    shell.setSize(150, 150);        Cursor cursor = new Cursor(display, new Image(display,"yourFile.gif").getImageData(), 0, 0);    shell.setCursor(cursor);    shell.open();    while (!shell.isDisposed()) {      if (!display.readAndDispatch())        display.sleep();    }    cursor.dispose();    display.dispose();  }}

参考资料:

1、Create Cursor from an Image

2、Taking a look at SWT Images



原创粉丝点击