Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » GridTableViewer - layout problem
GridTableViewer - layout problem [message #591685] Tue, 12 August 2008 08:44
Eclipse UserFriend
Originally posted by:

I am trying to display a GridTableViewer in a View, together with a
Composite that contains other widgets. I am running into some formatting
problems that are driving me crazy.

The following simplified code illustrates my problem.

If I incorporate the code as is, I get a GridTableViewer that displays
scrollbars, and fills the view as I expect.

However, if I uncomment the code labelled "###UNCOMMENT" in an attempt to
display a Composite with a Label above the GridTableViewer, I run into
problems. The scrollbars disappear, and the GridTableViewer no longer
fills the entire width of the view.

Any help with this would be much appreciated.

None of the examples I've found online combine a GridTableViewer with
another Composite in a view.



package my_package;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableFontProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.part.ViewPart;

import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
import org.eclipse.nebula.widgets.grid.GridColumn;

public class MyView extends ViewPart {

private GridTableViewer gridViewer;

public void createPartControl(Composite parent) {

// parent.setLayout(new GridLayout(1, false));
// parent.setLayoutData(new GridData(GridData.FILL));
// Composite topComposite = new Composite(parent, SWT.NONE);
// topComposite.setLayout(new GridLayout(3, false));
// topComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// Label label = new Label(parent, SWT.LEFT);
// label.setText("Test Label");

Composite tableComposite = new Composite(parent, SWT.NONE);
tableComposite.setLayout(new FillLayout());

gridViewer =
new GridTableViewer(
tableComposite, SWT.V_SCROLL | SWT.H_SCROLL);

gridViewer.setLabelProvider(new ColumnLabelProvider());
gridViewer.setContentProvider(new TableContentProvider());


GridColumn column1 = new GridColumn(gridViewer.getGrid(), SWT.NONE);
column1.setText("Column 1");

GridColumn column2 = new GridColumn(gridViewer.getGrid(), SWT.NONE);
column2.setText("Column 2");



* Passing the focus request to the viewer's control.
public void setFocus() {

class ColumnLabelProvider extends LabelProvider implements
ITableLabelProvider, ITableFontProvider, ITableColorProvider {

public Image getColumnImage(Object element, int columnIndex) {
// TODO Auto-generated method stub
return null;

public String getColumnText(Object element, int columnIndex) {
if (element instanceof TableRow) {
switch (columnIndex) {
case 0:
return ((TableRow)element).getC1();
case 1:
return ((TableRow)element).getC2();
return "TBD";
return "TBD";

public Font getFont(Object element, int columnIndex) {
// TODO Auto-generated method stub
return null;

public Color getBackground(Object element, int columnIndex) {
// TODO Auto-generated method stub
return null;

public Color getForeground(Object element, int columnIndex) {
// TODO Auto-generated method stub
return null;


class TableContentProvider implements IStructuredContentProvider {

private List<TableRow> tableRows;

public TableContentProvider() {
tableRows = new ArrayList<TableRow>();

for (int row=1; row<=100; row++) {
String c1 = "R" + row + " C1";
String c2 = "R" + row + " C2";
TableRow tableRow = new TableRow(c1, c2);

public Object[] getElements(Object inputElement) {
// TODO Auto-generated method stub
System.out.println("getElements called - length = " + tableRows.size());
return tableRows.toArray();

public void dispose() {
// TODO Auto-generated method stub


public void inputChanged(Viewer viewer, Object oldInput, Object
newInput) {
// TODO Auto-generated method stub



class TableRow {
private String c1;
private String c2;

public TableRow(String c1, String c2) {
this.c1 = c1;
this.c2 = c2;

public String getC1() {
return c1;

public String getC2() {
return c2;


Previous Topic:GridTableViewer - JFace Databinding - Dates
Next Topic:Grid: GridViewer selection service does not support cell selection
Goto Forum:

Current Time: Wed Jun 20 17:32:12 GMT 2018

Powered by FUDForum. Page generated in 0.01893 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top