Skip to main content


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 14:32 Go to next message
Peter Kullmann is currently offline Peter KullmannFriend
Messages: 240
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 14:40 Go to previous messageGo to next message
Timur Achmetow is currently offline Timur AchmetowFriend
Messages: 38
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 16:05 Go to previous messageGo to next message
Peter Kullmann is currently offline Peter KullmannFriend
Messages: 240
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).
Re: ScrolledForm Layout Problem [message #1220662 is a reply to message #1021180] Thu, 12 December 2013 23:25 Go to previous messageGo to next message
John Reysa is currently offline John ReysaFriend
Messages: 21
Registered: July 2009
Junior Member
You might try adding a section and limiting it's height which would in turn limit your table height.

Try replacing
form.getBody().setLayout(new GridLayout(1, false));

with
TableWrapLayout tableWrapLayout = new TableWrapLayout();
tableWrapLayout.numColumns = 1;
body.setLayout(tableWrapLayout);


Then create a section with TableWrapLayoutData and a composite where you put your table. Something like:

Section section = toolkit.createSection(body, Section.CLIENT_INDENT | Section.TITLE_BAR);
section.clientVerticalSpacing = 1;
TableWrapData twd = new TableWrapData(TableWrapData.FILL, TableWrapData.FILL);
twd.maxHeight = 400;
twd.grabVertical = true;
twd.grabHorizontal = true;
twd.rowspan = 1;
section.setLayoutData(twd);
section.setText("Title");

Composite composite = toolkit.createComposite(section, SWT.NONE);
section.setClient(composite);


The layout in adding the table to the composite did not seem to matter. Grid works. I didn't try this with your code, but it worked for me on another project.
Re: ScrolledForm Layout Problem [message #1232712 is a reply to message #1220662] Fri, 17 January 2014 14:48 Go to previous message
Peter Kullmann is currently offline Peter KullmannFriend
Messages: 240
Registered: July 2009
Senior Member
John, thanks for your example. In your case the table is fixed at 400 pixels height. I can do a fixed height table also without a section. The table should grow vertically if there is space available.

Regards,
Peter
Previous Topic:[Databinding] Put data to a WritableMap from other Thread
Next Topic:dynamic dispose and create of treeviewer + columns
Goto Forum:
  


Current Time: Fri Apr 26 00:34:37 GMT 2024

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

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

Back to the top