Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » FormLayout problem, using relative sizes
FormLayout problem, using relative sizes [message #459579] Thu, 11 August 2005 15:30
Ognen Ivanovski is currently offline Ognen IvanovskiFriend
Messages: 11
Registered: July 2009
Junior Member
Hi everyone,

I want to achieve the following using a FormLayout:

- I lay out n widgets in possbily several lines (one line can contain
more than one widget)
- I don't want to specify any widget size with pixels
- I want each widget's width to resize along with the form but with some
respect to the other widgets _in_the_same_line_.
- I want a reasonable preferred size (width) of the composite that
contains the widgets

I came up with the idea of giving a widget a relative size: it's size
in respect with the sizes of the other widgets _in_the_same_line_.

Suppose I have the wiggets A, B and C in one line, then

relativeSize(A) = 1
relativeSize(B) = 3
relativeSize(C) = 6

means that B is three times wider than A and C is 6 times wider than A
and 2 times wider than B.

Then I use the following trick to lay out these widgets in a line:

nominator = relativeSize(A) + relativeSize(B) + relativeSize(C)

Here's what i do:


Control controlA, controlB, ControlC; // some controls

FormData a = new FormData();
a.left = new FormAttachment(0, 5);
a.right = new FormAttachment(relativeSizeA, nominator, 0);

FormData b = new FormData();
b.left = new FormAttachment(controlA, 5);
b.right = new FormAttachment(relativeSizeA + relativeSizeB, nominator, 0);

FormData c = new FormData();
c.left = new FormAttachment(controlB, 5);
c.right = new FormAttachment(nominator, nominator, 0);

controlA.setLayoutData(a);
controlB.setLayoutData(b);
controlC.setLayoutData(c);


So far so good *but* this works well only if the container has a fixed
size (a shell).

When you put this form (composite) inside a ScrollableForm (jface) or
ScrollableComposite then the preffered of the composite comes into play
and it is usually too wide.

By looking at the FormLayout code I've seen that when computing the
preferred width of a composite with a FormLayout the FromLayout goes
through each widget, takes it's preferredWidth and looks how much must
the composite be wide so that the component's preferredWidth would fit
into the constraints given by the left and right attachments.

So if given the above code (a.right attachged to 1/10 of the whole
width) and

preferredWidth(A) = 40px

then the FormLayout would reason that the form needs to be at least

formSize(A) = 400px

wide in order that 40px of A will really be 1/10th of the form.

FormLayout then goes through each widget and finds the max(formSize(w))
and that is the preferred size of the form.

As I said this results in way too wide layout, mostly because a widget's
relative size is small comparing to the other widgets in the line but
it's preferred size is big (or the same) as with the other.

My queston is, given all this, how can I influence the preferred size of
the composite so it will be reasonable (not too wide)?

Setting formData.width comes into mind but I wanted to avoid dealing
with pixels.

Assigning an absoulte number of pixels (relativeSize = 1 ~ 40px) also is
an idea but....


Regards,
O.
--
____________________________________________________________ ____________
Ognen Ivanovski oivanovski@netcetera.com.mk
Netcetera Engineering phone +389 2 30 64 532
1000 Skopje, Macedonia fax +389 2 30 79 495
Previous Topic:TableViewer with ControlListener
Next Topic:How to tell what control is gaining focus when I'm losing focus?
Goto Forum:
  


Current Time: Sat Apr 17 00:43:50 GMT 2021

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

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

Back to the top