`
yuanzher
  • 浏览: 30533 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

使用TableViewer动态增加一行值时老是报错

阅读更多
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;

import dbclass.BarCode;
import dbclass.BarcodeEntity;
import dbdao.BarCodeDao;


public class SellerShell {
MainShell mainshell = new MainShell();
private Text goodsText;
//BarcodeEntity bce=new BarcodeEntity();
private TableViewer tv;
private List savalist;


public void opensheller(String seller) {
MainShell.shell.setVisible(false);
Shell newShell = new Shell(SWT.CLOSE|SWT.MIN);
SWTUtils.setCenter(newShell);
newShell.setText("销售窗口");
newShell.setSize(700,500);
newShell.setLayout(new GridLayout());
//newShell.setLayout(new FillLayout(SWT.VERTICAL));
newShell.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
if (!MainShell.shell.isVisible())
MainShell.shell.setVisible(true);
}
});
//窗口中的版块
GridData gd=null;
Composite header=new Composite(newShell,SWT.BORDER);
header.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
header.setLayout(new GridLayout(4,false));

Label hd_lb1=new Label(header,SWT.NONE);
// gd=new GridData();
// gd.horizontalSpan=4;
// hd_lb1.setLayoutData(gd);
hd_lb1.setLayoutData(createGridData(GridData.BEGINNING, 4));
hd_lb1.setText("销售员"+seller);

Label hd_lb2=new Label(header,SWT.NONE);
GridData hd_lb2_gd=new GridData();
hd_lb2_gd.horizontalIndent=100;
hd_lb2.setLayoutData(hd_lb2_gd);
hd_lb2.setText("请输入商品防伪条码");

goodsText = new Text(header,SWT.BORDER|SWT.RIGHT);
goodsText.setLayoutData(new GridData(150,-1));
//goodsText.setLayoutData(createGridData(GridData.FILL_HORIZONTAL, 2));

Button smite=new Button(header,SWT.PUSH);
smite.setText("确定");
//窗口中部
Composite body=new Composite(newShell,SWT.BORDER);
body.setLayoutData(new GridData(GridData.FILL_BOTH));
body.setLayout(new FillLayout());

tv=new TableViewer(body,SWT.MULTI|SWT.BORDER|SWT.FULL_SELECTION);
Table table=tv.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableLayout layout=new TableLayout();
table.setLayout(layout);
layout.addColumnData(new ColumnWeightData(30));
new TableColumn(table,SWT.NONE).setText("ID号");
layout.addColumnData(new ColumnWeightData(40));
new TableColumn(table,SWT.NONE).setText("商品名称");
layout.addColumnData(new ColumnWeightData(10));
new TableColumn(table,SWT.NONE).setText("单价");
layout.addColumnData(new ColumnWeightData(15));
new TableColumn(table,SWT.NONE).setText("购买数量");
layout.addColumnData(new ColumnWeightData(10));
new TableColumn(table,SWT.NONE).setText("合计");
tv.setContentProvider(new TableViewerContentProvider());
tv.setLabelProvider(new TableViewerLabelProvider());
//Object data=PeopleFactory.getPeoples();
////
// BarcodeEntity bce=new BarcodeEntity();
// smite.addSelectionListener(new SmiteSelectionListener(tv,bce,goodsText.getText()));
smite.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){

ArrayList bc_list=new BarCodeDao().getGoodsArrayList(goodsText.getText());
if(bc_list!=null){
Iterator itor=bc_list.iterator();
while (itor.hasNext()) {
BarcodeEntity bce=new BarcodeEntity();
BarCode barcode=(BarCode)itor.next();
bce.setBar_code(barcode.getBar_code());
bce.setGoods_name(barcode.getGoods_name());
bce.setGoods_price(barcode.getGoods_price());
bce.setGoods_count(1);
bce.setTotal(barcode.getGoods_price());

System.out.println(bce.getBar_code());
System.out.println(bce.getGoods_name());
System.out.println(bce.getGoods_count());
System.out.println(bce.getGoods_price());

tv.add(bce);

System.out.println(bce.getBar_code());
savalist=(List)tv.getInput();
savalist.add(bce);
System.out.println(bce.getBar_code());
}
return;
}
}
});


//窗口底部
Composite footer=new Composite(newShell,SWT.BORDER);
footer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
footer.setLayout(new GridLayout(4,false));
Label ft_lb=new Label(footer,SWT.NONE);
ft_lb.setText("总价");
Text ft_text=new Text(footer,SWT.BORDER|SWT.READ_ONLY|SWT.RIGHT);
new Label(footer,SWT.NONE).setText("元     ");
Button ft_add=new Button(footer,SWT.PUSH);
ft_add.setText("结算");

//System.out.print(ft_text.getTopPixel()+" "+ft_text.getTopIndex());
Button ft_print=new Button(footer,SWT.PUSH);
ft_print.setLayoutData(new GridData(GridData.END));
GridData ft_print_gd=new GridData();
ft_print_gd.horizontalSpan=4;
ft_print_gd.horizontalAlignment=GridData.END;
ft_print_gd.horizontalIndent=500;
ft_print.setLayoutData(ft_print_gd);
ft_print.setText("打印清单");
// int x=newShell.getSize().x;
// int y=newShell.getSize().y;
// System.out.print(x+"           "+y+"\n");



newShell.open();

}
private GridData createGridData(int style,int horizontalSpan){
GridData griddata=new GridData(style);
griddata.horizontalSpan=horizontalSpan;
return griddata;
}
}
就是在savalist.add(bce);
这一行老是报错,一运行到这一行,界面就自己没有了。希望哪位高手帮我解决一下,很急,毕业设计的。
另外其它的类都是按严格要求写的,应该没有错。
分享到:
评论
2 楼 yuanzher 2009-05-23  
我想问一下,可不可以在子窗口中再打开第三个窗口哇,做到一步时,又出错了,程序动不了了。请高手略介绍一种方法。
1 楼 yuanzher 2009-05-23  
   旧的问题还没有解决,新的问题又来了,我是个小菜鸟。

相关推荐

    Swt/Jface tableViewer入门教程一(显示tableViewer)

    在本文中,我们将深入探讨如何使用Swt/Jface库中的`tableViewer`组件来创建一个基本的表格视图。Swt(Standard Widget Toolkit)是Java中用于开发原生界面的应用程序开发工具包,而Jface是建立在Swt之上的抽象层,...

    TableViewer示例

    【TableViewer示例】——全面探索TableViewer的使用 在Java SWT(Standard Widget Toolkit)库中,TableViewer是一个强大的组件,用于在用户界面中展示表格数据。它提供了丰富的功能,如排序、过滤、编辑和自定义列...

    tableviewer edit

    在压缩包文件"example"中,可能包含了实现以上功能的示例代码或者一个完整的RCP应用实例,你可以通过查看这些文件来进一步理解和学习如何在Eclipse RCP中使用`TableViewer`和`CellEditor`。这有助于提升你在桌面应用...

    Set TableViewer Cell Focus

    在IT领域,特别是Java Swing和Eclipse RCP开发中,TableViewer是经常被用来展示数据的一个组件。"Set TableViewer Cell Focus"这个话题是关于如何在TableViewer中设置焦点到特定单元格上,这对于实现用户交互和数据...

    Tableviewer实现

    在Java开发领域,尤其是涉及到Swing或Eclipse RCP( Rich Client Platform)应用程序时,`TableViewer`是一个非常重要的组件。它允许开发者在用户界面中展示表格数据,并提供了丰富的功能来处理这些数据。本篇文章将...

    swt/jface tableViewer开发简化

    在Java中,反射机制允许程序在运行时检查类、接口、字段和方法的信息,甚至可以动态调用方法和改变对象状态。 综上所述,SWT/JFace的`tableViewer`开发涉及了GUI设计、数据模型绑定、事件处理和用户交互等多个方面...

    SWT中自己订制了一个TableViewer(用于我的列出项目中的所有错误信息),作为测试用的。与大家分享

    通过TableViewer,我们可以轻松地将数据模型与表视图关联起来,实现数据的动态更新和交互。 首先,我们需要创建一个TableViewer实例,并将其附加到Table控件上。这可以通过以下代码实现: ```java Table table = ...

    TableViewer单元格编辑功能

    Jface TableViewer控件实现的对标签文件的标签属性的修改功能。 用TextCellEditor和ComboBoxCellEditor给表格添加编辑功能。...如要应用到实际项目当中还需改变判断条件和TableViewer控件获得的值。

    Swt/Jface tableViewer入门教程三(加入在表格上直接编辑数据)

    在本文中,我们将深入探讨如何使用Swt/Jface库中的`TableViewer`组件来创建一个功能丰富的表格,并实现用户可以直接在表格上编辑数据的功能。Swt/Jface是Eclipse平台的一部分,提供了一套用于构建图形用户界面(GUI...

    JFace TableViewer的单元格逐个遍历的辅助类

    点击Enter键,对TableViewer的单元格进行逐个遍历的辅助类,推荐用于使用ViewerColumn.setEditingSupport的可编辑TableViewer。 Since 3.3, an alternative API is available, see ViewerColumn.setEditingSupport...

    RCP开发之TableViewer 列的显示与隐藏

    RCP开发比Table更高级的TableViewer的使用。实现列的隐藏与显示

    Setting focus cell in TableViewer

    2. "Tab between fields in TableViewer - Stack Overflow.mht" 可能是一个关于如何在TableViewer的不同单元格间使用tab键切换的问题和解答。 3. "jface TableViewer ViewerCell editElement based on Column - ...

    带有翻页功能的TableViewer.rar

    6. **事件处理**:确保TableViewer中的事件处理正确,例如,当用户选择某一行时,可以触发相应的事件,进行数据的详细查看或编辑。 在“带有翻页功能的TableViewer.rar”压缩包中,很可能包含了实现这些功能的Java...

    Plugins-JFace-TableViewer.rar

    Plugins-JFace-TableViewer.rar Plugins-JFace-TableViewer.rar Plugins-JFace-TableViewer.rar Plugins-JFace-TableViewer.rar Plugins-JFace-TableViewer.rar

    TableViewer学习源码

    虽然文件名字起得很笼统 里面只有一个关于TableViewer的项目源码 源码的依据是我转载的一篇学习TableViewer的博客源码 http://blog.csdn.net/weiweiwei256/article/details/49514699

    Eclipse从入门到精通2

    为了更好地理解TableViewer的使用方法,我们通过一个具体的示例来进行讲解: ##### 实例数据模型介绍 假设我们需要显示一个包含个人基本信息的数据表,每条记录包含以下字段:ID号(数值型)、姓名(字符型)、...

    swt_jface_celleditor

    3. 在TableViewer的`addColumn()`方法中,使用`setCellEditor()`指定单元格使用的编辑器。 4. 处理CellEditor的`applyEditorValue()`和`editElement()`方法,以确保数据的正确更新和验证。 5. 监听`valueChanged()`...

    HDFView_UsersGuide.pdf

    HDFView是一款用于查看和编辑HDF4和HDF5文件内容的图形化工具,本指南文档主要提供了HDFView的用户使用说明和HDF对象模型的简要介绍。 首先,HDFView可以用于查看和编辑HDF4和HDF5文件内容,这包括打开文件、查看...

    RCP 打开视图的不同实例,并设置不同的值,工程代码可运行

    RCP 打开视图的不同实例,并设置不同的值 ,创建一个视图,里面布局用了个tableviewer,通过一个Action,按钮打开该视图,每次打开的视图的内容可设置不同。 说明文档为 ...

    SWT Table单元格编辑功能

    在Java图形用户界面(GUI)开发中,SWT(Standard Widget Toolkit)是一个广泛使用的工具包,它提供了丰富的控件集合,用于构建高性能的桌面应用程序。其中,`Table`控件是SWT中最常用的数据展示组件之一,尤其适用...

Global site tag (gtag.js) - Google Analytics