Home » Eclipse Projects » JFace » GridLayoutFactory vs GridLayout
GridLayoutFactory vs GridLayout [message #2839] |
Sun, 10 May 2009 06:57  |
Eclipse User |
|
|
|
Hi,
I have a question about layouting, and in particular about the difference
between GridLayout and GridLayoutFactory.
If I'm right, the former belongs to SWT, while the latter to JFace:
anyway, except for the API documentation, I havn't been able to find any
kind of tutorial about GridLayoutFactory. Hasn't it been used too much?
I have just two TableViewers: I want the one on the left to fill the
space, and the one on the right to remain of a fixed size. I don't care
about this size, I just want it to be enough to see the contents of the
entries.
Here's my code:
parent.setLayout(new GridLayout(2, false));
leftViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL |
SWT.V_SCROLL);
leftViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
true));
Table table = new Table(parent, SWT.CHECK);
TableLayout layout = new TableLayout();
layout.addColumnData(new ColumnWeightData(100, false));
table.setLayout(layout);
table.setLinesVisible(true);
table.setHeaderVisible(true);
TableColumn tc0 = new TableColumn(table, SWT.NONE);
TableViewer rightViewer = new CheckboxTableViewer(table);
rightViewer.getTable().setLayoutData(new GridData(SWT.RIGHT, SWT.TOP,
false, false));
It works, but the table on the right isn't wide enough to see all its text.
Thanks for any suggestion.
|
|
|
Re: GridLayoutFactory vs GridLayout [message #2857 is a reply to message #2839] |
Mon, 11 May 2009 06:03   |
Eclipse User |
|
|
|
Hi Luca,
as the name suggests, GLF creates GridLayout objects. Similar is
GridDataFactory, which creates GridData objects. Both are made for
convenience, you can always achieve the same by directly creating the
objects. The main advantage of the factories is that you can assign the
layout and set properties in one single line. The setters always return
the factory itself, so you can chain the calls. In contrast to that,
configuring a GridData often requires a variable and several lines of code.
Luca D. wrote:
> I have just two TableViewers: I want the one on the left to fill the
> space, and the one on the right to remain of a fixed size. I don't
> care about this size, I just want it to be enough to see the contents
> of the entries.
> [...]
> It works, but the table on the right isn't wide enough to see all its
> text.
I'm not sure whether you can achieve this with a layout manager only.
Maybe you have to compute the required size of the table, set it on the
GridData and re-layout the GridLayout by calling layout().
Regards, Sebastian
|
|
|
Re: GridLayoutFactory vs GridLayout [message #2891 is a reply to message #2857] |
Mon, 11 May 2009 10:59  |
Eclipse User |
|
|
|
Luca,
Sebastian is right, GridLayoutFactory etc. is a pure convenience API, it
does not add any additional layout capabilities. It can also generate a
"default" layout that can be useful to further reduce the lines of code
needed to set up a layout. To use this, create widgets for one composite and
then call something like
GridLayoutFactory.fillDefaults().numColumns(2).generateLayou t(composite),
and then only set layout data for those widgets for which the defaults are
not quite right, using something like
GridDataFactory.defaultsFor(control).grab(true, false).applyTo(control).
But I guess this was not an answer to your actual question, which is really
about SWT layouts and probably best asked on the SWT newsgroup.
Boris
"Sebastian Paul" <sebastian.paul.ext@siemens.com> wrote in message
news:gu8t4p$9e6$1@build.eclipse.org...
> Hi Luca,
> as the name suggests, GLF creates GridLayout objects. Similar is
> GridDataFactory, which creates GridData objects. Both are made for
> convenience, you can always achieve the same by directly creating the
> objects. The main advantage of the factories is that you can assign the
> layout and set properties in one single line. The setters always return
> the factory itself, so you can chain the calls. In contrast to that,
> configuring a GridData often requires a variable and several lines of
> code.
>
> Luca D. wrote:
>> I have just two TableViewers: I want the one on the left to fill the
>> space, and the one on the right to remain of a fixed size. I don't care
>> about this size, I just want it to be enough to see the contents of the
>> entries.
>> [...]
>> It works, but the table on the right isn't wide enough to see all its
>> text.
>
> I'm not sure whether you can achieve this with a layout manager only.
> Maybe you have to compute the required size of the table, set it on the
> GridData and re-layout the GridLayout by calling layout().
>
> Regards, Sebastian
|
|
|
Goto Forum:
Current Time: Wed May 07 23:24:06 EDT 2025
Powered by FUDForum. Page generated in 0.03137 seconds
|