Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Aligning widgets within different composites
| | |
Re: Aligning widgets within different composites [message #538650 is a reply to message #538644] |
Tue, 08 June 2010 10:38 |
Vijay Raj 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 |
Geejay 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 |
Vijay Raj 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 )
---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
|
|
| | | | |
Goto Forum:
Current Time: Thu Sep 26 22:07:26 GMT 2024
Powered by FUDForum. Page generated in 0.04611 seconds
|