swt 表格的编辑的语法:
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setText("table放在选项框中的实例");
//sheet1
TabFolder sheet1 = new TabFolder(shell,SWT.NONE);
sheet1.setBounds(5, 5, 1000, 700);
TabItem item1 = new TabItem(sheet1,SWT.NONE);
item1.setText("sheet1");
Composite composite1 = new Composite(sheet1,SWT.NONE);
composite1.setBounds(5, 5, 180, 130);
final Table table1 = new Table(composite1,SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION );
table1.setBounds(0, 0, 900, 600);
table1.setVisible(true);
table1.setLinesVisible(true);
//table1.setItemCount(10);//?
TableColumn[] columns1 = new TableColumn[10];
for(int i = 0 ; i<10 ; i++){
columns1[i] = new TableColumn(table1,SWT.CENTER);
columns1[i].setText(i+"");
//columns1[i].setResizable(true);//?
columns1[i].setWidth(70);
}
TableItem temp = null;
for(int i = 0;i<10;i++){
temp = new TableItem(table1,SWT.NONE);
for(int j = 0;j<10;j++){
temp.setText(j, i+""+j);
}
}
item1.setControl(composite1);
table1.addListener(SWT.MouseDoubleClick, new Listener(){
@Override
public void handleEvent(Event event) {
Point point = new Point(event.x,event.y);
TableItem itm = table1.getItem(point);
if(itm == null)
return;
for(int i = 0;i<10;i++){
Rectangle rect = itm.getBounds(i);
if(rect.contains(point)){
System.out.println("列值"+i);
final TableEditor editor = new TableEditor(table1);
Control oldEditor = editor.getEditor();
if(oldEditor != null)
oldEditor.dispose();
Text textEditor = new Text(table1,SWT.NONE);
textEditor.computeSize(SWT.DEFAULT, table1.getItemHeight());
editor.grabHorizontal = true;
editor.minimumHeight = textEditor.getSize().y;
editor.minimumWidth = textEditor.getSize().x;
editor.setEditor(textEditor,itm,i);
textEditor.setFont(new Font(display,"宋体",10,SWT.ITALIC));
textEditor.setText(itm.getText(i));
textEditor.forceFocus();
final int myi = i;
textEditor.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
Text text = (Text)editor.getEditor();
text.setForeground(display.getSystemColor(SWT.COLOR_RED));
editor.getItem().setText(myi,text.getText());
}
});
textEditor.addFocusListener(new org.eclipse.swt.events.FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
System.out.println("失去焦点");
String text = ((Text)editor.getEditor()).getText();
editor.getEditor().dispose();
TableItem[] is = table1.getItems();
for(int i = 0;i<is.length;i++){
for(int j = 0;j<10;j++){
System.out.print( is[i].getText(j)+" ");
}
System.out.println();
}
}
});
}
}
}
});
TabItem item2 = new TabItem(sheet1,SWT.NONE);
item2.setText("sheet2");
Label l2 = new Label(sheet1,SWT.NONE);
l2.setBounds(5, 20, 40, 40);
l2.setText("第二个2");
item2.setControl(l2);
//shell.pack();
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
分享到:
相关推荐
org.eclipse.swt.SWT.class org.eclipse.swt.SWTError.class org.eclipse.swt.SWTException.class org.eclipse.swt.accessibility.ACC.class org.eclipse.swt.accessibility.Accessible.class org.eclipse.swt....
下载编译的SWT库,版本号4.911,包含多个版本: org.eclipse.swt.cocoa.macosx.x86_64 org.eclipse.swt.gtk.linux.aarch64 org.eclipse.swt.gtk.linux.arm org.eclipse.swt.gtk.linux.ppc64le org.eclipse.swt.gtk....
64位windows操作系统使用的SWT库
《Eclipse SWT/Jface核心应用》全面介绍了SWT、JFace和RCP的相关知识。全书共分5篇,第1篇介绍了SWT产生的背景以及SWT的一些基本概念和基础知识。第2篇介绍了SWT基本控件的使用,以及事件处理、布局等SWT基本知识的...
SWT examples,SWT官方例子:http://www.eclipse.org/swt/examples.php 该页面所要下载的例子 其中,swt的例子在\plugins\org.eclipse.swt.examples.source_3.7.0.v3740f.jar中
swt框架 适用与window下java窗口开发~~~~
swt 画图小程序 自由画线 矩形。。import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseMoveListener; ...
SWT-Internal-Video使用SWT技术对视频的常用显示功能进行了实现和封装,并提供了API。 它的接口之灵活性可以满足视频显示上的很多要求 与 情况。 SWT-Internal-Video解决的是程序与视频设备DVR/DVS之间的链接,并...
SWT配置 SWT配置 SWT配置 SWT配置 SWT配置 SWT配置 SWT配置 SWT配置
SWT官方api文档 开发基于swt的GUI程序必备手册
基本上关于swt_win32_extension该有的都有了,其中org.eclipse.swt.win32.jar并不是必须的,如果出现OS.class未找到异常等,就在构建路径里加上org.sf.feeling.swt.win32.extension_1.1.0.jar这个包就可以了。...
这是我找到的最全的SWT示例,即使在官方网站上也非常难找,示例包括以下内容:SWT模式窗体,SWT浏览器,SWT树,SWT工具条,SWT画图工具,SWT图形,SWT各种布局,SWT剪贴板,SWT快捷键,SWT菜单,SWT文本编辑器,SWT...
swt资源释放问题,详细介绍swt如何释放屏幕资源
swt运行时所需的dll文件,包括swt-awt-win32-3236.dll swt-gdip-win32-3236.dll swt-win32-3229.dll swt-win32-3236.dll
SWT本身仅仅是Eclipse组织为了开发 Eclipse IDE环境所编写的一组底层图形界面 API。或许是无心插柳,或是有意为之,至今为止,SWT无论是在性能和外观上,都超越了SUN公司提供的AWT和SWING。目前Eclipse IDE已经开发...
SWT Table 单元格编辑实例代码
JFace是建立在SWT之上的UI部件,是Eclipse组织为了开发Eclipse IDE环境所编写的一组底层图形界面 API,其底层实现为SWT。它扩展了 SWT并能与 SWT 交互操作。JFace工具箱提供了一组功能强大的用户界面组件,开发人员...
开发swt用的swt.jar包下载。资源分1分,记得评论哦~
swt table 实现换行
java SWT 基本窗口 组件 开发