我在从我创建的表中检索数据时遇到问题。它显示一个复选框,字符串(取自首先添加的all_mapping_objects)和下拉组合,值为0.0到1.0。如何在表中编辑后检索所有值,即复选框boolean,string value和combo value。
尝试了TableItem[] items = table.getItems()
的一些变体,但我只回到空值。
final Table table = new Table(sectionsInfo, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
table.setLinesVisible(true);
InfogridData = new GridData();
InfogridData.horizontalSpan = 4;
InfogridData.horizontalAlignment = GridData.BEGINNING;
InfogridData.horizontalAlignment = GridData.FILL;
InfogridData.grabExcessHorizontalSpace = true;
InfogridData.verticalAlignment = GridData.BEGINNING;
InfogridData.verticalAlignment = GridData.FILL;
InfogridData.grabExcessVerticalSpace= true;
TableColumn column = new TableColumn(table, SWT.NONE);
column.setWidth(500);
TableColumn column2 = new TableColumn(table, SWT.NONE);
column2.setWidth(50);
table.setLayoutData(InfogridData);
for (int i = 0; i < all_mapping_objects.size(); i++) {
new TableItem(table, SWT.NONE);
}
TableItem[] items = table.getItems();
for (int i = 0; i < items.length; i++) {
TableEditor editor = new TableEditor(table); //defines editor which controls objects put in
CCombo combo = new CCombo(table, SWT.NONE | SWT.READ_ONLY);
editor.grabHorizontal = true;
for (float me = 0; me <= 10; me++) {
combo.add("" + me/10);
}
combo.setText("1.0");
editor.setEditor(combo, items[i], 1); // sets the column
editor = new TableEditor(table);
Button button = new Button(table, SWT.CHECK);
button.setText(all_mapping_objects.get(i).getTextf()); // mapping objects written to the table
button.pack();
editor.minimumWidth = button.getSize().x;
editor.horizontalAlignment = SWT.LEFT;
editor.setEditor(button, items[i], 0); // sets the column
}
答案 0 :(得分:0)
您应该在Button ( SWT.CHECK)
上使用SelectionListener,对CCombo
也是如此。我建议您开始使用TableViewer
而不是使用SWT表。