当前位置:  编程技术>java/j2ee

SWT(JFace)体验之Icon任我变

    来源: 互联网  发布时间:2014-10-21

    本文导语:  代码如下 代码如下:package swt_jface.demo; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; impo...

代码如下
代码如下:

package swt_jface.demo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class IconSelector {
Display display = new Display();
Shell shell = new Shell(display);
Label labelIconFile;
Text textIconFile;

Button buttonIconBrowse;
Button buttonSetIcon;

Image shellIcon;

Image buttonIcon;

public IconSelector() {

initializeUI();

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

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}

private void initializeUI() {
GridLayout gridLayout = new GridLayout(3, false);
shell.setLayout(gridLayout);
labelIconFile = new Label(shell, SWT.NULL);

textIconFile = new Text(shell, SWT.SINGLE | SWT.BORDER);

GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.grabExcessHorizontalSpace = true;
textIconFile.setLayoutData(gridData);
buttonIconBrowse = new Button(shell, SWT.PUSH);
gridData = new GridData();
gridData.horizontalSpan = 3;
gridData.horizontalAlignment = GridData.CENTER;
buttonSetIcon = new Button(shell, SWT.PUSH);
buttonSetIcon.setLayoutData(gridData);
shell.setText("Icon Selector");
labelIconFile.setText("Select an icon:");
buttonIconBrowse.setText("Browse");
buttonSetIcon.setText("Set Icon");
buttonIconBrowse.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
String file = dialog.open();
if (file != null) {
textIconFile.setText(file);
}
}
});
buttonSetIcon.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if(shellIcon != null)
shellIcon.dispose();

try {
shellIcon = new Image(display, textIconFile.getText());
shell.setImage(shellIcon);
}catch(Exception ex) {
ex.printStackTrace();
}
}
});
}

public static void main(String[] args) {
new IconSelector();
}
}

    
 
 
 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • GUI 设计工具 SWT Designer
  • 基于SWT的图表库 SWTChart
  • 基于swt的控件 nebula
  • SWT的自动化测试框架 SWTBot
  • 基于SWT的HTML编辑器控件 Composer
  • java使用swt显示图片示例分享
  • SWT布局描述语言 XSWT
  • 打开lumaqq报错:no swt-win32-3224 in java.library.path
  • Java的Ribbon界面实现 SWT Ribbon
  • 本地化GUI组件库 SWT
  • 用Java Web Start + SWT还是用QT?
  • JAVA(SWT)仿visual studio GUI设计器


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3