首页 > 系统服务 > 详细

eclipse中按钮实现显示图像

时间:2017-10-28 01:01:01      阅读:525      评论:0      收藏:0      [点我收藏+]

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.SWT;
import swing2swt.layout.FlowLayout;

import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.graphics.*; //加载图像需要用的包


public class Ima {

protected Shell shell;
private Device display;

/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
Ima window = new Ima();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}

/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(685, 493);
shell.setText("SWT Application");
shell.setLayout(new FormLayout());

Composite composite = new Composite(shell, SWT.NONE);
FormData fd_composite = new FormData();
fd_composite.top = new FormAttachment(0, 10);
fd_composite.left = new FormAttachment(0, 10);
fd_composite.bottom = new FormAttachment(0, 436);
fd_composite.right = new FormAttachment(0, 657);
composite.setLayoutData(fd_composite);
composite.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

Button btnNewButton = new Button(composite, SWT.NONE);
btnNewButton.setText("按钮");

Image image=new Image(display,"C:\\Users\\lenovo\\Desktop\\8.jpg");
image.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
btnNewButton.setImage(image);

}

}

eclipse中按钮实现显示图像

原文:http://www.cnblogs.com/qhc1105543773/p/7745780.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!