Sri
Sri

Reputation: 699

How to reduce table size in Table viewer in RCP?

i have GridTableViewer, in that table showing rows are much.so i planned to reduce table height. But i am unable reduce the tableviewer size of the height.Can u anyone help me in this?

///pasting sample code

  @Override
        protected void addComponents(FormToolkit toolkit) {
            myTableViewr=
                    new ExtendedGridTableViewer(client, getPage(), SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
            Grid grid = myTableViewr.getGrid();
            toolkit.adapt(grid, false, false);
            grid.setHeaderVisible(true);
            grid.setCellSelectionEnabled(false);


            GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);

            grid.setLayoutData(gridData);
            List<ColumnType<?>> columns = new ArrayList<ColumnType<?>>();
            columns.add(new nameColumnType());
            columns.add(new valueColumnType());
            myTableViewr.createColumnGrid(toolkit, columns);

            //myModel - my model code
            LogoInsertionContentProvider contentProvide = new LogoInsertionContentProvider(this, myTableViewr, myModel);
            myTableViewr.setContentProvider(contentProvide);
            myTableViewr.setInput(myModel);
}

here, two columns and 3 rows only. but i am getting more than 10 rows

Upvotes: 0

Views: 164

Answers (1)

greg-449
greg-449

Reputation: 111142

Your GridData for the table is:

GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);

which is asking to grab all available space. If you want to use a fixed height for the table use something like:

GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
gridData.heightHint = 500;   // The height you want

Upvotes: 2

Related Questions