SWT Table mit Checkbox

saibot23

Grünschnabel
Hallo ich habe mir einen SWT Table mit Checkbox erzeugt (new Table(parent,SWT.CHECK | SWT.FULL_SELECTION)) ... jetzt fülle ich den ... klappt auch alles wunderbar.

Nur möchte ich bei einigen Zeilen die erste Spalte wo normalerweise die checkbox untergebracht ist leer lassen oder anders gesagt wie kann ich die checkbox eines TableItems entfernen? Bzw geht das überhaupt?
 
Du kannst das mit einem TableEditor lösen
Code:
Table table = new Table(parent,SWT.MULTI);
TableColumn column = new TableColumn(table,SWT.NONE);
column.setWidth(100);
column.setText("12");
TableColumn column2 = new TableColumn(table,SWT.NONE);
column2.setWidth(100);
column2.setText("12");
for(int i=0; i<20;i++){
   TableItem ti = new TableItem(table,SWT.NONE)
   if(i==5 || i==3 || i==12){
      Button check = new Button(table,SWT.CHECK);
      TableEditor tbl_editor = new TableEditor(table);
      tbl_editor.grabHorizontal=true;
      tbl_editor.minimumHeight=check.getSize().x;
      tbl_editor.minimumWidth=check.getSize().y;
      tbl_editor.setEditor(check,thisItem,0);
   }
    ti.setText(1,"Hallo");
}

Du kannst dan der Checkbox noch einen SelectionListener hinzufügen. Falls dir nicht klar ist wie dann meld dich nochmal!
 
Nochmal etwas genauer:
Code:
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.*;

public class ZeileAuswaehlen {

public static void main (String [] args) {
	Display display = new Display ();
	Shell shell = new Shell (display);
	shell.setLayout(new FillLayout());
	Table table = new Table(shell,SWT.MULTI);
	TableColumn column = new TableColumn(table,SWT.NONE);
	column.setWidth(100);
	column.setText("12");
	TableColumn column2 = new TableColumn(table,SWT.NONE);
	column2.setWidth(100);
	column2.setText("12");
	for(int i=0; i<20;i++){
	   TableItem ti = new TableItem(table,SWT.NONE);
	   if(i==5 || i==3 || i==12){
	      Button check = new Button(table,SWT.CHECK);
	      check.setData(i);
	      
	      check.addSelectionListener(new SelectionAdapter(){
	      	public void widgetSelected(SelectionEvent e){
	      		Button thisButton= (Button) e.widget;
	      		int zeilennummer=(Integer)thisButton.getData();
	      		if(thisButton.getSelection()){
	      			System.out.println("Zeile Nummer"+zeilennummer+"wurde ausgewählt");
	      		}
	      	}
	      });
	      TableEditor tbl_editor = new TableEditor(table);
	      tbl_editor.grabHorizontal=true;
	      tbl_editor.minimumHeight=check.getSize().x;
	      tbl_editor.minimumWidth=check.getSize().y;
	      tbl_editor.setEditor(check,ti,0);
	   }
	    ti.setText(1,"Hallo");
	}
	shell.setSize (200, 200);
	shell.open ();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}
}
 
Ja das ist ne Möglichkeit mit einem Button, da ich aber die Table nicht per Hand fülle sondern mittels Content und LableProvider geht das nicht, oder ich weiß nicht wie...

Mir ist halt nicht so ganz klar in welcher Klasse die Checkbox "eingebaut" wird beim Labelprovider wird ja nur der Text oder ein Bild zurückgegeben...:confused:
 
Code:
Table testTable = new Table(parent,SWT.CHECK | SWT.FULL_SELECTION);
		
		
		final CheckboxTableViewer testTableViewer = new CheckboxTableViewer(testTable);
		
		TableColumn checkColumn = new TableColumn(testTable, SWT.CENTER);
		checkColumn.setWidth(25);
		
		TableColumn codeColumn = new TableColumn(testTable, SWT.LEFT);
		codeColumn.setText("Code");
		codeColumn.setWidth(this.columWidthBig);
....

Code:
testTableViewer.setInput(makeInput(this.inTheTableList));

makeInput formt meine Liste zum passenden Model um

Jetzt würde ich gern zeile für Zeile durch die Table gehen können und in bestimmten zeilen die Checkbox enfernen....
 
Zurück