Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Aligning widgets within different composites
Aligning widgets within different composites [message #538607] Tue, 08 June 2010 08:03 Go to next message
Geejay is currently offline GeejayFriend
Messages: 160
Registered: February 2010
Senior Member
Hello all

Say I have a form with 3 columns.

I want to group say the bottom two rows into an SWT Group widget.

How do I tell the bottom two rows that they have to have the same column
size as the columns above, when they belong to a different parent and have a
different gridlayout object?

Poorly drawn ASCII example:

x x
x x
x x
yy yy
yy yy

The y's are the grouped widgets. They have their own GridLayout (set on the
Group composite). I want the column width to be the same for both sets of
widgets, e.g

x x
x x
x x
yy yy
yy yy

Thanks!

Greg
Re: Aligning widgets within different composites [message #538634 is a reply to message #538607] Tue, 08 June 2010 09:31 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
explore griddata.horzontalspan and deduce it...

---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: Aligning widgets within different composites [message #538644 is a reply to message #538634] Tue, 08 June 2010 09:59 Go to previous messageGo to next message
Geejay is currently offline GeejayFriend
Messages: 160
Registered: February 2010
Senior Member
I think I have confused you with my ASCII art. The double y's indicate a
single widget. Therefore span doesn't help me here.

"vijay" <vijay.rajonline@gmail.com> wrote in message
news:hul2l2$ie5$1@build.eclipse.org...
> explore griddata.horzontalspan and deduce it...
> --
> ---------------------
> why, mr. Anderson, why, why do you persist?
> Because I Choose To.
> Regards,
> Vijay
Re: Aligning widgets within different composites [message #538650 is a reply to message #538644] Tue, 08 June 2010 10:38 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
the double y represent a composite containing two buttons....

i understand that..now after seeing between the lines,the solution would be

package org.eclipse.swt.snippets;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;

public class Snippet
{
    static Display display;

    static Shell shell;

    public static void main(String[] args)
    {
        display = new Display();
        shell = new Shell(display);
        shell.setSize(300, 300);
        shell.open();
        shell.setLayout(new GridLayout(5, true));
        for (int i = 0; i < 15; i++)
        {
            Button button = new Button(shell, SWT.PUSH);
            button.setText("B" + (i + 1));
            GridData layoutData = new GridData();
            layoutData.grabExcessHorizontalSpace = true;
            button.setLayoutData(layoutData);
        }
        Composite composite = new Group(shell, SWT.NONE);
        composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        composite.setLayout(new GridLayout(2, false));
        GridData layoutData = new GridData();

        Button button = new Button(composite, SWT.PUSH);
        button.setText("B16");
        Button button1 = new Button(composite, SWT.PUSH);
        button1.setText("B17");
        composite.setLayoutData(layoutData);

        Composite composite1 = new Group(shell, SWT.NONE);
        composite1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        composite1.setLayout(new GridLayout(2, false));
        GridData layoutData1 = new GridData();

        Button button11 = new Button(composite1, SWT.PUSH);
        button11.setText("B16");
        Button button12 = new Button(composite1, SWT.PUSH);
        button12.setText("B17");
        composite1.setLayoutData(layoutData);
        shell.layout();
        while (!shell.isDisposed())
        {
            if (!display.readAndDispatch()) display.sleep();
        }
        display.dispose();
    }
}


changing

GridData layoutData = new GridData();
layoutData.grabExcessHorizontalSpace = true;
button.setLayoutData(layoutData);

to

GridData layoutData = new GridData(GridData.FILL_HORIZONATL);
button.setLayoutData(layoutData);

also would be what u want...


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay

[Updated on: Tue, 08 June 2010 10:40]

Report message to a moderator

Re: Aligning widgets within different composites [message #538665 is a reply to message #538650] Tue, 08 June 2010 11:32 Go to previous messageGo to next message
Geejay is currently offline GeejayFriend
Messages: 160
Registered: February 2010
Senior Member
You'll notice in this example the columns are aligned with the group, not
the button within the group.

I need to align the widgets (buttons in this example) in the groups, to the
widgets in another control (for example the parent composite, the section
above the groups in the example).

Here is a diagram of what I am trying to achieve:
y y
---------
| x x |
---------

The y's need to be aligned with the x's in the group.

Let me know if you do not understand the question.


"vijay" <vijay.rajonline@gmail.com> wrote in message
news:hul6io$53c$1@build.eclipse.org...
> the double y represent a composite containing two buttons....
>
> i understand that..now after seeing between the lines,the solution would
> be
>
> package org.eclipse.swt.snippets;
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Group;
> import org.eclipse.swt.widgets.Shell;
>
> public class Snippet
> {
> static Display display;
>
> static Shell shell;
>
> public static void main(String[] args)
> {
> display = new Display();
> shell = new Shell(display);
> shell.setSize(300, 300);
> shell.open();
> shell.setLayout(new GridLayout(5, true));
> for (int i = 0; i < 15; i++)
> {
> Button button = new Button(shell, SWT.PUSH);
> button.setText("B" + (i + 1));
> GridData layoutData = new GridData();
> layoutData.grabExcessHorizontalSpace = true;
> button.setLayoutData(layoutData);
> }
> Composite composite = new Group(shell, SWT.NONE);
> composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
> true));
> composite.setLayout(new GridLayout(2, false));
> GridData layoutData = new GridData();
>
> Button button = new Button(composite, SWT.PUSH);
> button.setText("B16");
> Button button1 = new Button(composite, SWT.PUSH);
> button1.setText("B17");
> composite.setLayoutData(layoutData);
>
> Composite composite1 = new Group(shell, SWT.NONE);
> composite1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
> true));
> composite1.setLayout(new GridLayout(2, false));
> GridData layoutData1 = new GridData();
>
> Button button11 = new Button(composite1, SWT.PUSH);
> button11.setText("B16");
> Button button12 = new Button(composite1, SWT.PUSH);
> button12.setText("B17");
> composite1.setLayoutData(layoutData);
> shell.layout();
> while (!shell.isDisposed())
> {
> if (!display.readAndDispatch()) display.sleep();
> }
> display.dispose();
> }
> }
>
> --
> ---------------------
> why, mr. Anderson, why, why do you persist?
> Because I Choose To.
> Regards,
> Vijay
Re: Aligning widgets within different composites [message #538679 is a reply to message #538665] Tue, 08 June 2010 12:10 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
ok now i got u r requirement

Quote:
package org.eclipse.swt.snippets;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;

public class Snippet
{
static Display display;

static Shell shell;

public static void main(String[] args)
{
display = new Display();
shell = new Shell(display);
shell.setSize(300, 300);
shell.open();
shell.setLayout(new GridLayout(5, true));
GridData layoutData = new GridData(SWT.CENTER, SWT.TOP, true, false);
// layoutData.widthHint = 20;
for (int i = 0; i < 15; i++)
{
Button button = new Button(shell, SWT.PUSH);
button.setText("B" + (i + 1));

button.setLayoutData(layoutData);
}
GridData layoutData1 = new GridData(GridData.FILL_HORIZONTAL);
layoutData1.horizontalSpan = 2;
Composite composite = new Group(shell, SWT.NONE);
composite.setLayoutData(layoutData1);
GridLayout layout = new GridLayout(2, false);

layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);

Button button = new Button(composite, SWT.PUSH);
button.setText("B16");
button.setLayoutData(layoutData);
Button button1 = new Button(composite, SWT.PUSH);
button1.setText("B17");
button1.setLayoutData(layoutData);

Composite composite1 = new Group(shell, SWT.NONE);
composite1.setLayoutData(layoutData1);
composite1.setLayout(layout);

Button button11 = new Button(composite1, SWT.PUSH);
button11.setText("B16");
button11.setLayoutData(layoutData);
Button button12 = new Button(composite1, SWT.PUSH);
button12.setText("B17");
button12.setLayoutData(layoutData);
shell.layout();
while (!shell.isDisposed())
{
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}



this is the closest it can get....

if u want a perfect dynamic match,i think it would not be possible...

by the way i am the same guy answering "Getting column width from GridLayout " query

thats why i told u forget that query concentrate on this one...
(i am just trying to help Smile )


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: Aligning widgets within different composites [message #538688 is a reply to message #538665] Tue, 08 June 2010 12:09 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

geejay wrote:
> You'll notice in this example the columns are aligned with the group,
> not the button within the group.

Why not use either GridLayout or FormLayout and put them all in one
parent? multiple composites side-by-side are not a good solution for a
layout or alignment problem.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Aligning widgets within different composites [message #538689 is a reply to message #538688] Tue, 08 June 2010 12:16 Go to previous messageGo to next message
Geejay is currently offline GeejayFriend
Messages: 160
Registered: February 2010
Senior Member
But I would like to use the SWT Group widget if possible. And the way I
understand it the Group becomes the parent composite of the controls.

It sounds like it is pretty much impossible.

Is there a way to reparent a subset of the widgets to a group afterwards,
and maintain the original alignment?

"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:hulbok$or1$2@build.eclipse.org...
> geejay wrote:
>> You'll notice in this example the columns are aligned with the group, not
>> the button within the group.
>
> Why not use either GridLayout or FormLayout and put them all in one
> parent? multiple composites side-by-side are not a good solution for a
> layout or alignment problem.
>
> PW
>
>
> --
> Paul Webster
> http://wiki.eclipse.org/Platform_Command_Framework
> http://wiki.eclipse.org/Command_Core_Expressions
> http://wiki.eclipse.org/Menu_Contributions
> http://wiki.eclipse.org/Menus_Extension_Mapping
> http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm
Re: Aligning widgets within different composites [message #538691 is a reply to message #538689] Tue, 08 June 2010 12:26 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

geejay wrote:
> But I would like to use the SWT Group widget if possible. And the way I
> understand it the Group becomes the parent composite of the controls.
>
> It sounds like it is pretty much impossible.
>
> Is there a way to reparent a subset of the widgets to a group
> afterwards, and maintain the original alignment?

No, that doesn't work ... however ...

If you're willing to manage it you can manage your own layout for the
second group. If your first group is correctly laid out, you can use
button.setBounds(*) on your second set of buttons ... or use the Layout
protocol and actually write a Layout:

group1 ( button1 button2 )
group2 ( button3 button 4 )
group2.setLayout(new MyLayout(group1))

You would have to do the position calculations yourself, but you could
keep group2 in alignment with group1


PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Aligning widgets within different composites [message #538694 is a reply to message #538689] Tue, 08 June 2010 12:30 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
IIRC MigLayout can position controls across composite borders. You can
install an OSGified version from
http://download.eclipse.org/tools/orbit/downloads/drops/R201 00114021427/

Tom

Am 08.06.10 14:16, schrieb geejay:
> But I would like to use the SWT Group widget if possible. And the way I
> understand it the Group becomes the parent composite of the controls.
>
> It sounds like it is pretty much impossible.
>
> Is there a way to reparent a subset of the widgets to a group
> afterwards, and maintain the original alignment?
>
> "Paul Webster" <pwebster@ca.ibm.com> wrote in message
> news:hulbok$or1$2@build.eclipse.org...
>> geejay wrote:
>>> You'll notice in this example the columns are aligned with the group,
>>> not the button within the group.
>>
>> Why not use either GridLayout or FormLayout and put them all in one
>> parent? multiple composites side-by-side are not a good solution for
>> a layout or alignment problem.
>>
>> PW
>>
>>
>> --
>> Paul Webster
>> http://wiki.eclipse.org/Platform_Command_Framework
>> http://wiki.eclipse.org/Command_Core_Expressions
>> http://wiki.eclipse.org/Menu_Contributions
>> http://wiki.eclipse.org/Menus_Extension_Mapping
>> http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm
>
>
Previous Topic:Getting column width from GridLayout
Next Topic:Tightly Coupling Parent-Children Tableviewers
Goto Forum:
  


Current Time: Fri Apr 19 22:37:24 GMT 2024

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

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

Back to the top