View unanswered posts | View active topics It is currently Fri May 26, 2017 5:47 pm

Reply to topic  [ 1 post ] 
 JFace TableViewer and MigLayout - Scrollbars 
Author Message

Joined: Wed Jun 15, 2011 10:37 am
Posts: 3
Post JFace TableViewer and MigLayout - Scrollbars
Hello! I am quite fond of MigLayout and I use it in my RCP project to create forms and the like. I also used it for SWT Composites containing a JFace TableViewer or JFace TreeViewer that scroll in both directions (SWT.H_SCROLL | SWT.V_SCROLL). Unfortunately I did not manage to configure MigLayout in a way that scrollbars are shown when I resize the Window (a Shell or RCP View, does not matter) so that the table is larger than the window (in which case scrollbars should appear; note: Scrollbars appear whenever the Table's contents are larger than the Tables size; obviously the table's size is not reduced according to the reduction in size of the window).

The following runnable snippet demonstrates the problem (note: you'll need SWT and JFace libraries, for example obtained by creating a RCP project with eclipse). When I use a normal FillLayout or GridLayout everything works fine. But how do I have to configure the MigLayout to achieve the same result (see lines 67/68)? Thanks for your help


package myrcpdemo;

import net.miginfocom.swt.MigLayout;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellLabelProvider;
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.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TableColumn;

public class SomeClass {

   private final TableViewer tableViewer;

   public SomeClass(final Shell shell) {
      tableViewer = new TableViewer(shell, SWT.V_SCROLL | SWT.H_SCROLL
            | SWT.BORDER);
      final CellLabelProvider labelProvider = new CellLabelProvider() {
         public void update(final ViewerCell cell) {
            final String text = ((MyModel) cell.getElement()).getText(cell
      for (int i = 0; i < 10; i++) {
         final TableColumn column = new TableColumn(tableViewer.getTable(), SWT.NONE);
         column.setText("Column " + i);
         final TableViewerColumn viewerColumn = new TableViewerColumn(tableViewer, column);
      tableViewer.setContentProvider(new ArrayContentProvider());
      final MyModel[] elements = new MyModel[10];
      for (int i = 0; i < 10; i++) {
         elements[i] = new MyModel(i);

   public TableViewer getTableViewer() {
      return tableViewer;

   public class MyModel {
      public int counter;

      public MyModel(final int counter) {
         this.counter = counter;

      public String getText(final int columnIndex) {
         return "Item " + counter + " - Column " + columnIndex;

   public static void main(final String[] args) {
      final Display display = new Display();

      final Shell shell = new Shell(display);
      // shell.setLayout(new FillLayout());
      shell.setLayout(new MigLayout());

      new SomeClass(shell);;
      while (!shell.isDisposed()) {
         if (!display.readAndDispatch()) {

Wed Jun 15, 2011 10:49 am
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.