eclipse的swt插件的控件

来源:互联网 发布:sql语句升序降序 编辑:程序博客网 时间:2024/04/30 01:58
SWT 各控件(文本框、消息框、组合框、表)的使用 持续更新中。。。
2009-10-25 20:25
SWT text(文本框)
Text text ;
// 添加单行文本框
text =new Text(shell, SWT.BORDER);
// 添加右对齐单行文本框
text =new Text(shell, SWT.RIGHT | SWT.BORDER);
// 添加以密码形式显示的文本框
text =new Text(shell, SWT.PASSWORD | SWT.BORDER);
// 添加只读文本框
text =new Text(shell, SWT.READ_ONLY | SWT.BORDER).setText("Read Only");


SWT messagebox:(消息框)


MessageBox msgbox=new MessageBox(shell,SWT.ICON_WARNING|SWT.OK|SWT.CANCEL);
msgbox.setMessage(“Please ”); //设置消息内容
if(msgbox.open()==SWT.OK)
{
.....
return;
}

常用的消息框类型有:SWT.ICON_WARNING, SWT.ICON_INFORMATION
常用组合:SWT.YES|SWT.NO  , SWT.OK|SWT.CANCEL

SWT ComboBox:(组合框)
Combo comboNameOfUnit;
String szTmp ="“要添加的内容";
comboNameOfUnit.add(szTmp ); //添加要显示的内容
comboNameOfUnit.select(0);  //默认选择第一项

SWT TABLE:(表)
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
//创建表
Table tableSearch = new Table(groupDisplay, SWT.BORDER); //设置表的基本属性,如有边框
tableSearch.setLinesVisible(true); 
tableSearch.setHeaderVisible(true);
tableSearch.setBounds(10, 26, 454, 101);
//删除表的记录
tableSearch.removeAll();
//删除表的所有列
int nTableColumn = tableSearch.getColumnCount();
for (int i=0; i<nTableColumn; i++)
{
tableSearch.getColumn(0).dispose();
}
//增加列

String[] columnHead={"id号",“名字”};
int COLUMN_WIDTH = 65;
TableColumn[] tableColumn = new TableColumn[columnHead.length];
for (int i=0; i<columnHead.length; i++)
{
        tableColumn[i] = new TableColumn(tableSearch, SWT.NONE); //绑定到表tableSearch
tableColumn[i].setText(columnHead[i]);  //设置属性名
tableColumn[i].setWidth(COLUMN_WIDTH); //设置每列的宽度
}
//增加记录
String[] szValue={"122","张三"};
TableItem tableItem = new TableItem(tableSearch, SWT.NONE);
tableItem.setText(szValue);  //设置将要显示的记录String数组

 

原创粉丝点击