SWT table with more than 200 columns does not display properly

In our Eclipse RCP 3.7 application, we download Excel files and display the first 30 rows in the table, the problem with rendering is not in the rows, but in the number of columns, when it reaches a certain size, the table does not look right, and when you scroll to the right, cells and headers fail, and all this just goes crazy.

The separate class below demonstrates this problem and follows the main pattern that I used in my application in case the problem occurs.

Any thoughts on how to solve this problem?

import java.util.ArrayList; import java.util.List; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.StyledCellLabelProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.jface.viewers.ViewerCell; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; public class Snippet { public static TableViewer viewer; public static void main( String[] args ) { Display display = new Display(); Shell shell = new Shell( display ); shell.setLayout( new FillLayout() ); viewer = new TableViewer(shell, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); Table table = viewer.getTable(); table.setLinesVisible(true); table.setHeaderVisible(true); viewer.setContentProvider(new ArrayContentProvider()); createColumns(300); viewer.setInput(generateData(300, 30)); for (TableColumn c : viewer.getTable().getColumns()) { c.pack(); } shell.setSize( 300, 500 ); shell.open(); while( !shell.isDisposed() ) { if( !display.readAndDispatch() ) { display.sleep(); } } display.dispose(); } private static void createColumns(int columnCount) { for (int i = 0; i < columnCount; i++) { createTableViewerColumn(i); } } private static TableViewerColumn createTableViewerColumn(int colNum) { final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE); final TableColumn column = viewerColumn.getColumn(); column.setText("Table Header " + colNum); column.setWidth(100); column.setResizable(true); column.setMoveable(false); viewerColumn.setLabelProvider(new Snippet.SampleDataTableCellProvider(colNum)); return viewerColumn; } private static List<String[]> generateData(int cols, int rows) { ArrayList<String[]> result = new ArrayList<String[]>(); for (int y = 0; y < rows; y++) { String[] row = new String[cols]; for (int x = 0; x < cols; x++) { row[x] = "Big long string to test how long these columns can go before it all goes mental."; } result.add(row); } return result; } private static class SampleDataTableCellProvider extends StyledCellLabelProvider { private int colnumber; private SampleDataTableCellProvider(int colnumber) { this.colnumber = colnumber; } @Override public void update(ViewerCell cell) { String[] row = (String[]) cell.getElement(); if (row.length > colnumber) { cell.setText(row[colnumber]); } else { cell.setText(""); } super.update(cell); } } } 
+4
source share
2 answers

I think TableViewer cannot update and render content fast enough while it scrolls.

You can try looking at the style of SWT.VIRTUAL and the lazy content providers for JFace viewers.

From javadoc TableViewer :

Starting with 3.1, TableViewer now supports the SWT.VIRTUAL flag. If the base table is SWT.VIRTUAL, the content provider can implement ILazyContentProvider instead of IStructuredContentProvider.

A TableViewer with the SWT.VIRTUAL style can use ILazyContentProvider to create and display content on demand. See Javadoc for some side effects of using virtual viewers, for example. restrictions on sorting or filtering.

See also this blog post: JFaces Viewers Performances .

Since the standard TableViewer caches rows, not columns, the GridTableViewer nebula seems more appropriate for the problem with a large number of columns. It informs about visible cells and can be used with LazyColumnLabelProvider .

For a solution using the GridTableViewer nebula GridTableViewer see this article: JFace-Viewer and Eclipse Databinding s> 10,000 Objects .

+5
source
-1
source

All Articles