eclipse 下关于Table删除行问题!急

w563847254 2010-08-13 12:01:48
我在table中添加了一些Text、Button、Combo组件,删除的时候都释放掉了,能够实现删除一行,现在的问题是我删除了之后要用鼠标点下下面的行才能填补上来,请问这是什么情况?怎么解决?急急急!
...全文
339 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
忘了隐藏 2010-08-13
  • 打赏
  • 举报
回复
删除的时候刷新下表试试呢
kanwy 2010-08-13
  • 打赏
  • 举报
回复
建议使用tableviewer,可以删除的。
不用重新查询、重新加载数据。
可以把table里面显示的数据对象都取出来,从删除占位起,后面的前移,然后刷新。一年前有接触过一模一样的功能开发。呵呵
w563847254 2010-08-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 martin_jay 的回复:]

删除后,重新调用获取列表的方法。使得后台重新查询数据,前台重新加载数据。
[/Quote]
上面是我的代码,麻烦帮我看看具体怎么操作,谢谢!
w563847254 2010-08-13
  • 打赏
  • 举报
回复
public void createTable(Group group){
final ScrolledComposite scrolledComposite=new ScrolledComposite(group ,SWT.BORDER
| SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setBounds(10, 30, 850, 500);
final Composite composite = new Composite(scrolledComposite, SWT.NONE);
composite.setBounds(0, 0, 820, 450);
table = new Table(composite,SWT.FULL_SELECTION | SWT.BORDER);
table.setBounds(0, 0, 750, 300);
table.setLinesVisible(true);
table.setHeaderVisible(true);
//table.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
table.addListener(SWT.MeasureItem, new Listener(){
public void handleEvent(Event event) {
event.width = table.getGridLineWidth();
event.height = (int)Math.floor(event.gc.getFontMetrics().getHeight()*1.5);
}
});
final Hashtable<Long,Vector> hashtable= new Hashtable<Long,Vector>();
String columnName[] = {"","通道ID","标号","斜率","截距","数字输入数","小数点",
"有效数字位","单位","数据通道类型","输入种类","高位报警","低位报警",
"警报号","最高有效数据","最低有效数据","有效百分比","描述","记录报告1",
"记录报告2","记录报告3","记录报告4","串口输出","备用文件输出"};
TableColumn column[] = new TableColumn[24];
for(int i=0;i<24;i++){
column[i] = new TableColumn(table,SWT.NONE);
column[i].setWidth(90);
column[i].setText(columnName[i]);
}
column[0].setWidth(30);
final Button button1 = new Button(composite,SWT.FLAT),
button2 = new Button(composite,SWT.FLAT);
button1.setBounds(10, 310, 100, 25);
button2.setBounds(500,310,100,25);
button1.setText("添加通道");
button2.setText("删除通道");
button1.addSelectionListener(new SelectionAdapter(){

int i = 1;
public void widgetSelected(SelectionEvent e){

Vector<TableEditor> editors = new Vector<TableEditor>();
TableItem tab = new TableItem(table,SWT.NONE);
tab.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
long tableRowNum = tab.hashCode();
TableEditor editor[] = new TableEditor[23];
for(int j=0;j<23;j++){
editor[j] = new TableEditor(table);
editor[j].grabHorizontal = true;
editors.add(editor[j]);
}
hashtable.put(tableRowNum, editors);
Text text[] = new Text[14];
String[] textStr1={""+i,"C"+i,"1","0","1","2","5"
,"0","0","0","0","0","75",""};
for(int j=0;j<text.length;j++){
text[j] = new Text(table,SWT.NONE);
text[j].setText(textStr1[j]);
}
for(int j=0;j<7;j++){
editor[j].setEditor(text[j], tab, j+1);
}
CCombo combo[] = new CCombo[3];
for(int j=0;j<3;j++){
combo[j] = new CCombo(table,SWT.READ_ONLY | SWT.SIMPLE);
}
String str1[]={"ppm","pphm","ppb","mg/m3","ug/m3","C","F","deg","mbar",
"m/s","kph","mph","%","mgHg","Mm-1","W/m"};
String str2[]={"Voltage","Frequency","Counter","NO","NOX","NO2",
"Concentration","Deviation","Light Level","Logger","CH4","NMHC",
"THC","H2S","TRS","O3","CO","NH3","SO2","Nx","WS","WD"};
String str3[]={"Average","Total","Std Dev","Max","Min","Max Time","Min Time"};
combo[0].setItems(str1);
combo[1].setItems(str2);
combo[2].setItems(str3);
for(int j=0;j<3;j++){
combo[j].select(0);
editor[7+j].setEditor(combo[j],tab,7+j+1);
}
for(int j=0;j<7;j++){
editor[10+j].setEditor(text[7+j], tab, 10+j+1);
}
Button checkBut[] = new Button[6];
for(int j=0;j<6;j++){
checkBut[j] = new Button(table,SWT.CHECK | SWT.CENTER);
checkBut[j].setSelection(true);
checkBut[j].pack();
editor[17+j].setEditor(checkBut[j], tab, 17+j+1);
}
i++;
tableRowNum++;
}
});
button2.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){

int row = table.getSelectionIndex();
if(row == -1)
return;
table.remove(row);
long rowNum = table.getItem(row).hashCode();
//table.getItem(row).dispose();

Iterator<Long> iterator = hashtable.keySet().iterator();
if(iterator!=null){
while(iterator.hasNext()){
Long key = iterator.next();
if(key==null){
return;
}
if(key == rowNum){
Vector editors = (Vector)hashtable.get(key);
Iterator eiter = editors.iterator();
while(eiter.hasNext()){
TableEditor editor = (TableEditor) eiter.next();
editor.getEditor().dispose();
editor.dispose();
}
hashtable.remove(key);
//table.getItem(row).dispose();
table.redraw();
table.update();
break;
}
}
}
}
});
}
Martin_Jay 2010-08-13
  • 打赏
  • 举报
回复
删除后,重新调用获取列表的方法。使得后台重新查询数据,前台重新加载数据。
w563847254 2010-08-13
  • 打赏
  • 举报
回复
redraw(),update()都试过了!

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧