我在从我创建的表中检索数据时遇到问题。它显示一个复选框、字符串(取自首先添加的 all_mapping_objects)和值 0.0 到 1.0 的下拉组合。在表格中编辑完所有值后,如何检索所有值,即复选框布尔值、字符串值和组合值。
尝试了一些变体,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
}