java jface table_JAVA.SWT/JFace: SWT高级控件之表格(Table、TableItem和Ta...

JAVA.SWT/JFace: SWT高级控件之表格(Table、TableItem和TableColumn)

2010年07月31日 星期六 23:18

《Eclipse SWT/JFACE 核心应用》 清华大学出版社 9.9 表格(Table、TableItem和TableColumn)

SWT中的表格是用Table、TableItem和TableColumn对象来表示数据。

书中删除TableItem时,未删除绑定的Text和CCombo,在下面的代码中做了修正。

import java.util.Hashtable;

public class TableSample {

public class TableItemControls{

Text text;

CCombo combo;

TableEditor tableeditor;

TableEditor tableeditor1;

public TableItemControls(Text text, CCombo combo,

TableEditor tableeditor, TableEditor tableeditor1) {

//    super();

this.text = text;

this.combo = combo;

this.tableeditor = tableeditor;

this.tableeditor1 = tableeditor1;

}

public void dispose()

{

text.dispose();

combo.dispose();

tableeditor.dispose();

tableeditor1.dispose();

}

};

private Shell sShell = null; // @jve:decl-index=0:visual-constraint="10,10"

private ViewForm viewForm = null;

private ToolBar toolBar = null;

private Composite composite = null;

private Table table = null;

private Menu menu = null;

private Hashtable tablecontrols = new Hashtable();

//创建ViewForm面板放置工具栏和表格

private void createViewForm() {

viewForm = new ViewForm(sShell, SWT.NONE);

viewForm.setTopCenterSeparate(true);

createToolBar();

viewForm.setTopLeft(toolBar);

createComposite();

viewForm.setContent(composite);

}

//创建工具栏

private void createToolBar() {

toolBar = new ToolBar(viewForm, SWT.FLAT);

final ToolItem add = new ToolItem(toolBar, SWT.PUSH);

add.setText("添加");

add.setImage( ImageFactory.loadImage( toolBar.getDisplay() , ImageFactory.ADD_OBJ));

final ToolItem del = new ToolItem(toolBar, SWT.PUSH);

del.setText("删除");

del.setImage( ImageFactory.loadImage( toolBar.getDisplay() , ImageFactory.DELETE_OBJ));

final ToolItem back = new ToolItem(toolBar, SWT.PUSH);

back.setText("上移");

back.setImage( ImageFactory.loadImage( toolBar.getDisplay() , ImageFactory.BACKWARD_NAV));

final ToolItem forward = new ToolItem(toolBar, SWT.PUSH);

forward.setText("下移");

forward.setImage( ImageFactory.loadImage( toolBar.getDisplay() , ImageFactory.FORWARD_NAV));

final ToolItem save = new ToolItem(toolBar, SWT.PUSH);

save.setText("保存");

save.setImage( ImageFactory.loadImage( toolBar.getDisplay() , ImageFactory.SAVE_EDIT));

//工具栏按钮事件处理

Listener listener = new Listener(){

public void handleEvent(Event event) {

//如果单击添加按钮,添加一行,在实际的项目实现中通常是接收输入的参数,案后添加

//这里为了简单起见,添加固定的一条记录

if ( event.widget == add )

{

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值