Freitag, 18. Dezember 2015

SWT Table or JFace TableViewer height problem with preloaded data

When implementing a new function to a SWT/JFace bases dialog I encountered a problem when data is loaded into the table before it is visible.

The TableViewer is placed in a GridLayout and should grab available vertical und horizontal space. Therefor I applied th follwing GridData:

viewer.getControl().setLayoutData(
    new GridData(SWT.FILL, SWT.FILL, true, true));

The layout was fine since I loaded no data via the setInput() method of the TableViewer. As soon as I loaded data into the TableViewer the Table height increased to display all rows without scrollbars. The scrollbars then appeared in DetailsPart where the TableViewer was placed in.

The following picture illustrates the problem:

Messy scrollbars

This is pretty aweful because the buttons also scroll up and the form is unusable.

I tried several code-changes to bring the scrollbars to the TableViewer. When data is loaded after the GUI showed up everything was fine. Unfortunately I could not manage to get it working in the JFace master/details pattern.

The I remembered the GridDataFactory and modified the setLayoutData call for the TableViewer:

viewer.getControl().setLayoutData(GridDataFactory.defaultsFor(
    viewer.getControl()).grab(true, true).align(SWT.FILL, SWT.FILL)
   .create());

And that did the trick!

The defaultsFor() does something more so the scrollbars always appear at the TableViewer even if a large amount of data is loaded before the GUI shows up.

Scrollbars display correctly at the TableViewer





Keine Kommentare:

Kommentar veröffentlichen