views:

271

answers:

1

I am trying to embed a JFace TableViewer in a SWT TabFolder, but when I do so, the table does not show up. The current (working code) in my GitToDo code looks like (see this Git repos):

    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Git ToDo");
    FillLayout layout = new FillLayout();
    shell.setLayout(layout);

    final GitToDoTree tableViewer = new GitToDoTree(shell);

Where the latter GitToDoTree extends TableViewer, with this constructor:

    super(parent, SWT.SINGLE | SWT.FULL_SELECTION | SWT.FILL);
    this.shell = parent;
    table = this.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

So, when I construct the TableViewer-extending GitToDoTree from a Shell it works, but as soon as I try to build it from a TabFolder or (tried that too) a Composite, nothing shows up anymore.

How can I get my TableViewer to show up in the TabFolder?

+2  A: 

If your TableViewer class isn't showing up when you add it to a Composite I would say that chances are that you are not setting a layout for the nested Composite.

final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Git ToDo");
FillLayout layout = new FillLayout();
shell.setLayout(layout);

Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(new FillLayout()); // Possible missing layout?

final GitToDoTree tableViewer = new GitToDoTree(composite);

And as for the TabFolder that may be that you are not setting the client control on the TabItem

TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
TabItem item = new TabItem(tabFolder, SWT.NONE);
item.setText("Table");

GitToDoTree viewer = new GitToDoTree(tabFolder);
item.setControl(viewer.getTable()); // Possible setControl call?

TabItem item2= new TabItem(tabFolder, SWT.NONE);
item2.setText("Empty");
Yanamon
Yeah, that worked! Thanx so very much!
Egon Willighagen
See commit: http://github.com/egonw/gtd/commit/4d198e5cbe796ea8430f42eb397d366064d1b1e5
Egon Willighagen