0

I'm trying to show 2 table viewers and buttons in between them. When trying to achieve the TableViewer to show horizontal and vertical scroll bars, I'm unable to see the TableViewer, only ScrolledComposite can be seen. I even tried creating a composite inside the ScrolledComposite and used that composite for showing TableViewer but still cannot see the TableViewer. Can someone point me in the right direction.

@Override
protected Control createDialogArea(Composite parent) {
    GridData gridData = new GridData(SWT.NONE, SWT.FILL, true, true);
    gridData.heightHint = 500;
    gridData.widthHint = 700;
    Composite parentComposite = new Composite(parent, SWT.NONE);
    parentComposite.setLayout(new GridLayout(3, true));
    parentComposite.setLayoutData(gridData);
    ScrolledComposite scrolledComposite_1 = new ScrolledComposite(parentComposite, SWT.H_SCROLL|SWT.V_SCROLL);
    scrolledComposite_1.setLayout(new GridLayout(1,false));
    gridData = new GridData(SWT.NONE, SWT.FILL, true, true);
    gridData.heightHint = 200;
    gridData.widthHint = 400;
    scrolledComposite_1.setLayoutData(gridData);
    scrolledComposite_1.setAlwaysShowScrollBars(true);
    TableViewer tableViewer1 = new TableViewer(scrolledComposite_1, SWT.BORDER | SWT.SINGLE);
    tableViewer1.getTable().setHeaderVisible(true);
    tableViewer1.getTable().setLayout(new GridLayout(1,false));
    tableViewer1.getTable().setLayoutData(new GridData(200,400));
    createButtonComposite(parentComposite,SWT.NONE);
    ScrolledComposite scrolledComposite_2 = new ScrolledComposite(parentComposite, SWT.H_SCROLL|SWT.V_SCROLL);
    scrolledComposite_2.setLayout(new GridLayout(1,false));
    gridData = new GridData(SWT.NONE, SWT.FILL, true, true);
    gridData.heightHint = 200;
    gridData.widthHint = 400;
    scrolledComposite_2.setLayoutData(gridData);
    scrolledComposite_2.setAlwaysShowScrollBars(true);
    TableViewer tableViewer2= new TableViewer(scrolledComposite_2, SWT.BORDER | SWT.SINGLE);
    tableViewer2.getTable().setHeaderVisible(true);
    tableViewer2.getTable().setLayoutData(new GridData(200,400));
    getShell().setText("My Dialog"); 
    return parent;
}
flavio.donze
  • 7,432
  • 9
  • 58
  • 91
Juseeth
  • 467
  • 1
  • 6
  • 18

1 Answers1

1

ScrolledComposite requires you to call setContents to tell it the child control and also requires varies other settings. This works:

scrolledComposite_1.setContent(tableViewer1.getTable());
scrolledComposite_1.setExpandVertical(true);
scrolledComposite_1.setExpandHorizontal(true);
scrolledComposite_1.setMinSize(tableViewer1.getTable().computeSize(SWT.DEFAULT, SWT.DEFAULT));

(and the same for the 2nd)

However TableViewer can display scroll bars itself so you don't really need ScrolledComposite at all:

Composite parentComposite = new Composite(parent, SWT.NONE);
parentComposite.setLayout(new GridLayout(3, true));
parentComposite.setLayoutData(gridData);

TableViewer tableViewer1 = new TableViewer(parentComposite, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
tableViewer1.getTable().setHeaderVisible(true);
tableViewer1.getTable().setLayout(new GridLayout(1,false));
tableViewer1.getTable().setLayoutData(new GridData(200,400));

createButtonComposite(parentComposite,SWT.NONE);

TableViewer tableViewer2= new TableViewer(parentComposite, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
tableViewer2.getTable().setHeaderVisible(true);
tableViewer2.getTable().setLayoutData(new GridData(200,400));
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • I'm able to achieve the layout what I want, but now I'm using ListViewer in SWT isnatead of TableViewer here, Is there any way that I can add click listener instead of DoubClickListener to it. – Juseeth Mar 10 '16 at 02:11
  • That should be a new question. – greg-449 Mar 10 '16 at 07:36