上午初學者到SWT,請人幫忙, 我的問題是: 我有一個表,其中有10列, 第一列具有複選框和列的其餘部分是從數據庫填充, 當我檢查複選框我想,要選擇perticular行,如何選擇整個TableViewer的行時複選框點擊(表中的第一列各行中的複選框)
我正在粘貼下面我表的代碼,
public static void main(String arg[])
{
// shell and display declared here
mainTable = new TableViewer(content, SWT.H_SCROLL| SWT.V_SCROLL | SWT.BORDER |SWT.DM_FILL_BACKGROUND|SWT.FULL_SELECTION);
mainTable .getTable().setHeaderVisible(true);
mainTable .getTable().setLinesVisible(true);
mainTable .setContentProvider(new ArrayContentProvider());
// COLUM FOR PLACING THE CHECK BOXES
TableColumn columncOL=new TableColumn(mainTable .getTable(),SWT.NONE);
columncOL.setText("");
columncOL.setWidth(40);
TableViewerColumn columnaC=new TableViewerColumn(mainTable ,columncOL);
columnaC.setLabelProvider(new ColumnLabelProvider(){
Map<Object, Button> buttons = new HashMap<Object, Button>();
@Override
public void update(ViewerCell cell) {
TableItem item = (TableItem) cell.getItem();
Button button;
if(buttons.containsKey(cell.getElement()))
{
button = buttons.get(cell.getElement());
}
else
{
button = new Button((Composite) cell.getViewerRow().getControl(),SWT.CHECK);
String s = "Item 1";
button.setData(s, "Some other info or object here");
s = "Item 2";
button.setData(s, "This is item two");
//buttons.put(cell.getElement(), button);
}
TableEditor editor = new TableEditor(item.getParent());
editor.grabHorizontal = true;
editor.grabVertical = true;
editor.setEditor(button , item, cell.getColumnIndex());
editor.layout();
}
});
// CREATING 1st COLUMNS
TableColumn column1Head=new TableColumn(mainTable.getTable(),SWT.NONE);
column1Head.setText("col1");
column1Head.setWidth(200);
// setting column input
TableViewerColumn column1=new TableViewerColumn(mainTable,column1Head);
column1.setLabelProvider(new ColumnLabelProvider()
{
public String getText(Object Element)
{
Student ap=(Student)Element;
return ap.col1();
}
});
}
像這樣創建了剩餘8列 我想在選中一個perticluar複選框時選擇整個行。 任何一個pleeeease幫助我儘可能早....
有沒有使用'CheckboxTableViewer'理由嗎? –
格雷格,實際上我不關於CheckboxTableViewer。我如何使用它?我可以使用而不是Tableviewer嗎?要麼 ?你可以舉一個小例子... – Msn