Search code examples
javaeclipseswtrcp

SWT.Table behaves differently with same code (Eclipse RCP)


Every second line is coloured on the table in the view.

I have the same table twice on the editor, but it doesn't show this separation:

My code of the lower table in the editor:

table1 = new Table(c, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION
            | SWT.V_SCROLL);
    TableLayout layout1 = new TableLayout();
    table1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    layout1.addColumnData(new ColumnWeightData(20, 50, true));
    layout1.addColumnData(new ColumnWeightData(20, 50, true));
    layout1.addColumnData(new ColumnWeightData(20, 50, true));
    layout1.addColumnData(new ColumnWeightData(20, 50, true));

    table1.setLayout(layout1);
    table1.setLinesVisible(true);
    table1.setHeaderVisible(true);

    TableColumn colReihe = new TableColumn(table1, SWT.LEFT);
    colReihe.setText("Reihe");
    TableColumn colPlatz = new TableColumn(table1, SWT.LEFT);
    colPlatz.setText("Platz");
    TableColumn colPreis = new TableColumn(table1, SWT.LEFT);
    colPreis.setText("Preis");
    TableColumn colStatus = new TableColumn(table1, SWT.LEFT);
    colStatus.setText("verkauft");

    this.tableViewer2 = new TableViewer(table1);
    this.tableViewer2.setContentProvider(new ArrayContentProvider());
    this.tableViewer2.setLabelProvider(new ITableLabelProvider() {
            ....some more code here....
            this.toolkit.adapt(table1, true, true);

Solution

  • I don't really understand your question. Do you expect the table on the lower right of your screenshot to look like the table on the left? If that's the question, check, whether you call toolkit.adapt(table, true, true); with the left table as well, or try to remove that call with the right table. The FormToolkit sets a lot of colors and styles on widgets.