Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » ScrolledForm Layout Problem(Howto create a layout with scrolled form an a large table)
ScrolledForm Layout Problem [message #1020201] Sun, 17 March 2013 10:32 Go to next message
Peter Kullmann is currently offline Peter Kullmann
Messages: 188
Registered: July 2009
Senior Member
Hi, I'm struggling to create a layout where there is a single table inside a scrolled form. I would like to show at least 10 items of the table. If there is not enough vertical space, the scrolled form should let me scroll to these items. If there are more than 10 items in the table we would even have two vertical scrollbars.
If the available space is larger I would like to see no scrollbars on the form. The table should expand to the bottom.
Sounds simple enough, but I didn't manage so far, In all my attempts the table is so high that it can show all elements (which are already present at that time) and the form shows a scroll bar.
When I try to limit the height of the table (setting a hight hint), it stays in that height - but I would like it to expand down.

Any help is greatly appreciated
Peter

Re: ScrolledForm Layout Problem [message #1021112 is a reply to message #1020201] Tue, 19 March 2013 10:40 Go to previous messageGo to next message
Timur Achmetow is currently offline Timur Achmetow
Messages: 36
Registered: April 2012
Member
What kind of Table you are use?
If you work with JFace TableViewer, that is not a problem,
I work with this code:

new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);


That give you automatic scrollbars, if the view will be smaller than the table.
Re: ScrolledForm Layout Problem [message #1021180 is a reply to message #1021112] Tue, 19 March 2013 12:05 Go to previous message
Peter Kullmann is currently offline Peter Kullmann
Messages: 188
Registered: July 2009
Senior Member
Thanks for your answer. Yes, I'm using JFace table viewers. Here is a snippet that illustrates my problem:

package snippets;

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

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;

public class TestScrolledForm {
	public static void main(String[] args) {
		Display display = new Display();
		final Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());

		FormToolkit toolkit = new FormToolkit(display);
		ScrolledForm form = toolkit.createScrolledForm(shell);
		form.getBody().setLayout(new GridLayout(1, false));

		TableViewer viewer = new TableViewer(form.getBody(), SWT.MULTI
				| SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
		GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getControl());
		
		viewer.setContentProvider(new ArrayContentProvider());
		
		List<String> data = new ArrayList<String>();
		for (int i = 0; i < 100; i++) {
			data.add("Item "+i);
		}
		viewer.setInput(data);

		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		toolkit.dispose();
		display.dispose();
	}

}


If you run this example you will get a large Table widget can show all items (without scroll bars) and a ScrolledComposite that allows scrolling the table (which is the situation I'd like to avoid).
Previous Topic:[Databinding] Put data to a WritableMap from other Thread
Next Topic:dynamic dispose and create of treeviewer + columns
Goto Forum:
  


Current Time: Sat May 18 20:54:01 EDT 2013

Powered by FUDForum. Page generated in 0.03285 seconds