Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » limiting tree control height with formlayout
limiting tree control height with formlayout [message #485669] Mon, 14 September 2009 12:27 Go to next message
Matthew Dickie is currently offline Matthew Dickie
Messages: 56
Registered: July 2009
Member
Hi all,

I am having difficult limiting the height of a tree control with
FormLayout. The code is below:

Tree dbTree = getWidgetFactory().createTree(composite, SWT.SINGLE |
SWT.V_SCROLL);
fDBTreeViewer = new TreeViewer(dbTree);
formData = new FormData();
formData.left = new FormAttachment(0, 0);
formData.right = new FormAttachment(100, 0);
formData.top = new FormAttachment(0, 0);
// formData.bottom = new FormAttachment(100, 0);
final int NUM_ROWS = 10;
FontMetrics fontMetrics =
FigureUtilities.getFontMetrics(parent.getFont());
formData.height = fontMetrics.getHeight() * NUM_ROWS;
dbTree.setLayoutData(formData);

I set the auto expand for the viewer to 2. If there are many items at
this level then the tree control becomes very tall and looks ridiculous.
(The tree control is part of a section within a TabbedPropertySheet).

As you can see I do set the height of the formData to 10 * font height,
but that doesn't seem to do anything. If I don't set auto expand to 2,
then with just 1 root element, the tree control is ridiculously short,
perhaps only 2 rows tall. Uncommenting out the line where
formData.bottom is set appears to make little difference either.

How can I set the height of the tree control to consistently be 10 rows
tall?

Thanks in advance,

Matt D.
Re: limiting tree control height with formlayout [message #486152 is a reply to message #485669] Wed, 16 September 2009 14:26 Go to previous message
Grant Gayed is currently offline Grant Gayed
Messages: 2151
Registered: July 2009
Senior Member
Hi Matt,

Putting your code into a snippet (with minor changes that should not make a
difference) seems to work for me, the snippet is pasted below. Maybe it's
not a problem with your Tree's FormData, but with its parent Composite?

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

Tree dbTree = new Tree(shell, SWT.SINGLE | SWT.V_SCROLL);
for (int i = 0; i < 99; i++) {
TreeItem root = new TreeItem(dbTree, SWT.NONE);
root.setText("root " + i);
TreeItem item = root;
for (int j = 0; j < 99; j++) {
item = new TreeItem(item, SWT.NONE);
item.setText("descendent " + j);
}
root.setExpanded(true);
}
dbTree.setLinesVisible(true);
//TreeViewer fDBTreeViewer = new TreeViewer(dbTree);
FormData formData = new FormData();
formData.left = new FormAttachment(0, 0);
formData.right = new FormAttachment(100, 0);
formData.top = new FormAttachment(0, 0);
// formData.bottom = new FormAttachment(100, 0);
final int NUM_ROWS = 10;
// FontMetrics fontMetrics =
shell.getFont().getFontData().FigureUtilities.getFontMetrics (parent.getFont(
));
formData.height = /*fontMetrics.getHeight()*/dbTree.getItemHeight() *
NUM_ROWS;
dbTree.setLayoutData(formData);

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

HTH,
Grant


"Matt Dickie" <m.dickie@querix.com> wrote in message
news:h8lcte$kfq$1@build.eclipse.org...
> Hi all,
>
> I am having difficult limiting the height of a tree control with
> FormLayout. The code is below:
>
> Tree dbTree = getWidgetFactory().createTree(composite, SWT.SINGLE |
> SWT.V_SCROLL);
> fDBTreeViewer = new TreeViewer(dbTree);
> formData = new FormData();
> formData.left = new FormAttachment(0, 0);
> formData.right = new FormAttachment(100, 0);
> formData.top = new FormAttachment(0, 0);
> // formData.bottom = new FormAttachment(100, 0);
> final int NUM_ROWS = 10;
> FontMetrics fontMetrics =
> FigureUtilities.getFontMetrics(parent.getFont());
> formData.height = fontMetrics.getHeight() * NUM_ROWS;
> dbTree.setLayoutData(formData);
>
> I set the auto expand for the viewer to 2. If there are many items at
> this level then the tree control becomes very tall and looks ridiculous.
> (The tree control is part of a section within a TabbedPropertySheet).
>
> As you can see I do set the height of the formData to 10 * font height,
> but that doesn't seem to do anything. If I don't set auto expand to 2,
> then with just 1 root element, the tree control is ridiculously short,
> perhaps only 2 rows tall. Uncommenting out the line where
> formData.bottom is set appears to make little difference either.
>
> How can I set the height of the tree control to consistently be 10 rows
> tall?
>
> Thanks in advance,
>
> Matt D.
Previous Topic:Problems using Component Browser
Next Topic:adding event to a line
Goto Forum:
  


Current Time: Mon Oct 20 21:16:15 GMT 2014

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

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