码迷,mamicode.com
首页 > 系统相关 > 详细

eclipse中按钮实现显示图像

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

标签:swing   tom   jpg   swt   splay   phi   sdi   open   .sh   

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中按钮实现显示图像

标签:swing   tom   jpg   swt   splay   phi   sdi   open   .sh   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!