Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Widget layout
Widget layout [message #446814] |
Thu, 02 December 2004 20:08 |
John Messages: 52 Registered: July 2009 |
Member |
|
|
Hi All,
I have created my own widget that contains a table control. The problem I am
currently having is the widget only takes up 1 horizontal span of the
composite. My example contains one row of a label and text control followed
below by my widget. Directly using a table control instead of my widget
works fine.
I would appreciate any ideas/help.
public MyExample(Composite parent) {
setLayout(parent);
addControls(parent);
}
private void setLayout(Composite composite) {
// Create a composite to hold the children
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
// Set numColumns for the buttons
int numColumns = 2;
GridLayout layout = new GridLayout(numColumns, false);
layout.marginWidth = 4;
composite.setLayout (layout);
}
public void addControls(Composite container) {
Label label = new Label(container, SWT.NONE);
label.setText("Testing");
// create text control
Text control = new Text(container, SWT.BORDER | SWT.SINGLE);
final GridData gridData = new GridData(GridData.FILL_HORIZONTAL |
GridData.VERTICAL_ALIGN_END);
gridData.horizontalSpan = 2;
control.setLayoutData(gridData);
// create my widget
int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL |
SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
MyTableWidget widget = new MyTableWidget(parent, style);
}
public MyTableWidget(Composite parent, int style) {
super(parent, SWT.NONE);
// Set GridLayout
int numColumns = 4; // default;
Layout data = (Layout) parent.getLayout();
if (data instanceof GridLayout) {
numColumns = ((GridLayout) data).numColumns;
}
GridLayout layout = new GridLayout(numColumns, false);
setLayout(layout);
// Set composite layout
GridData gridData = new GridData(GridData.FILL_BOTH);
//setLayoutData(gridData);
table = new Table(this, style);
// Set table layout
gridData.horizontalSpan = numColumns;
table.setLayoutData(gridData);
// Show lines and header
table.setLinesVisible(true);
table.setHeaderVisible(true);
}
|
|
|
Re: Widget layout [message #446836 is a reply to message #446814] |
Fri, 03 December 2004 16:02 |
Veronika Irvine Messages: 1272 Registered: July 2009 |
Senior Member |
|
|
You need to set the layout data on MyTableWidget
public MyTableWidget(Composite parent, int style) {
.....
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan = numColumns;
this.setLayoutData(gridData);
table = new Table(this, style);
gridData = new GridData(GridData.FILL_BOTH);
table.setLayoutData(gridData);
....
}
"John" <j_cout_nospam@yahoo.com> wrote in message
news:consnu$sg1$1@www.eclipse.org...
> Hi All,
> I have created my own widget that contains a table control. The problem I
> am
> currently having is the widget only takes up 1 horizontal span of the
> composite. My example contains one row of a label and text control
> followed
> below by my widget. Directly using a table control instead of my widget
> works fine.
> I would appreciate any ideas/help.
>
> public MyExample(Composite parent) {
>
> setLayout(parent);
> addControls(parent);
> }
>
> private void setLayout(Composite composite) {
>
> // Create a composite to hold the children
> composite.setLayoutData(new GridData(GridData.FILL_BOTH));
>
> // Set numColumns for the buttons
> int numColumns = 2;
> GridLayout layout = new GridLayout(numColumns, false);
> layout.marginWidth = 4;
> composite.setLayout (layout);
> }
>
>
> public void addControls(Composite container) {
>
> Label label = new Label(container, SWT.NONE);
> label.setText("Testing");
>
> // create text control
> Text control = new Text(container, SWT.BORDER | SWT.SINGLE);
> final GridData gridData = new GridData(GridData.FILL_HORIZONTAL |
> GridData.VERTICAL_ALIGN_END);
> gridData.horizontalSpan = 2;
> control.setLayoutData(gridData);
>
> // create my widget
> int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL |
> SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
>
> MyTableWidget widget = new MyTableWidget(parent, style);
>
>
> }
>
> public MyTableWidget(Composite parent, int style) {
>
> super(parent, SWT.NONE);
>
> // Set GridLayout
> int numColumns = 4; // default;
> Layout data = (Layout) parent.getLayout();
> if (data instanceof GridLayout) {
> numColumns = ((GridLayout) data).numColumns;
> }
>
> GridLayout layout = new GridLayout(numColumns, false);
> setLayout(layout);
>
> // Set composite layout
> GridData gridData = new GridData(GridData.FILL_BOTH);
> //setLayoutData(gridData);
>
> table = new Table(this, style);
>
> // Set table layout
> gridData.horizontalSpan = numColumns;
> table.setLayoutData(gridData);
>
> // Show lines and header
> table.setLinesVisible(true);
> table.setHeaderVisible(true);
> }
>
>
>
|
|
|
Re: Widget layout [message #446859 is a reply to message #446836] |
Fri, 03 December 2004 16:17 |
John Messages: 52 Registered: July 2009 |
Member |
|
|
Thanks Veronika,
I have another question regarding the layout. In my widget which extends
Composite, I call super(parent, SWT.NONE); When the widget is displayed
there is a certain amount of area (border) that is lost. Hence, the
alignment between controls above the widget and the widget is slightly off
i.e. the widget is narrowed on all sides. How do I reclaim this lost border
space.
thanks.../john
"Veronika Irvine" <veronika_irvine@oti.com> wrote in message
news:coq2nc$ld9$1@www.eclipse.org...
> You need to set the layout data on MyTableWidget
>
> public MyTableWidget(Composite parent, int style) {
>
> ....
>
> GridData gridData = new GridData(GridData.FILL_BOTH);
> gridData.horizontalSpan = numColumns;
> this.setLayoutData(gridData);
>
> table = new Table(this, style);
> gridData = new GridData(GridData.FILL_BOTH);
> table.setLayoutData(gridData);
> ...
> }
>
> "John" <j_cout_nospam@yahoo.com> wrote in message
> news:consnu$sg1$1@www.eclipse.org...
> > Hi All,
> > I have created my own widget that contains a table control. The problem
I
> > am
> > currently having is the widget only takes up 1 horizontal span of the
> > composite. My example contains one row of a label and text control
> > followed
> > below by my widget. Directly using a table control instead of my widget
> > works fine.
> > I would appreciate any ideas/help.
> >
> > public MyExample(Composite parent) {
> >
> > setLayout(parent);
> > addControls(parent);
> > }
> >
> > private void setLayout(Composite composite) {
> >
> > // Create a composite to hold the children
> > composite.setLayoutData(new GridData(GridData.FILL_BOTH));
> >
> > // Set numColumns for the buttons
> > int numColumns = 2;
> > GridLayout layout = new GridLayout(numColumns, false);
> > layout.marginWidth = 4;
> > composite.setLayout (layout);
> > }
> >
> >
> > public void addControls(Composite container) {
> >
> > Label label = new Label(container, SWT.NONE);
> > label.setText("Testing");
> >
> > // create text control
> > Text control = new Text(container, SWT.BORDER | SWT.SINGLE);
> > final GridData gridData = new GridData(GridData.FILL_HORIZONTAL |
> > GridData.VERTICAL_ALIGN_END);
> > gridData.horizontalSpan = 2;
> > control.setLayoutData(gridData);
> >
> > // create my widget
> > int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL |
> > SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
> >
> > MyTableWidget widget = new MyTableWidget(parent, style);
> >
> >
> > }
> >
> > public MyTableWidget(Composite parent, int style) {
> >
> > super(parent, SWT.NONE);
> >
> > // Set GridLayout
> > int numColumns = 4; // default;
> > Layout data = (Layout) parent.getLayout();
> > if (data instanceof GridLayout) {
> > numColumns = ((GridLayout) data).numColumns;
> > }
> >
> > GridLayout layout = new GridLayout(numColumns, false);
> > setLayout(layout);
> >
> > // Set composite layout
> > GridData gridData = new GridData(GridData.FILL_BOTH);
> > //setLayoutData(gridData);
> >
> > table = new Table(this, style);
> >
> > // Set table layout
> > gridData.horizontalSpan = numColumns;
> > table.setLayoutData(gridData);
> >
> > // Show lines and header
> > table.setLinesVisible(true);
> > table.setHeaderVisible(true);
> > }
> >
> >
> >
>
>
|
|
|
Re: Widget layout [message #446864 is a reply to message #446859] |
Fri, 03 December 2004 19:18 |
John Messages: 52 Registered: July 2009 |
Member |
|
|
Hi All,
Found the solution, has to do with the margins. Thanks.
GridLayout layout = new GridLayout(numColumns, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
setLayout(layout);
"John" <j_cout_nospam@yahoo.com> wrote in message
news:coq3hl$nll$1@www.eclipse.org...
> Thanks Veronika,
>
> I have another question regarding the layout. In my widget which extends
> Composite, I call super(parent, SWT.NONE); When the widget is displayed
> there is a certain amount of area (border) that is lost. Hence, the
> alignment between controls above the widget and the widget is slightly off
> i.e. the widget is narrowed on all sides. How do I reclaim this lost
border
> space.
> thanks.../john
>
> "Veronika Irvine" <veronika_irvine@oti.com> wrote in message
> news:coq2nc$ld9$1@www.eclipse.org...
> > You need to set the layout data on MyTableWidget
> >
> > public MyTableWidget(Composite parent, int style) {
> >
> > ....
> >
> > GridData gridData = new GridData(GridData.FILL_BOTH);
> > gridData.horizontalSpan = numColumns;
> > this.setLayoutData(gridData);
> >
> > table = new Table(this, style);
> > gridData = new GridData(GridData.FILL_BOTH);
> > table.setLayoutData(gridData);
> > ...
> > }
> >
> > "John" <j_cout_nospam@yahoo.com> wrote in message
> > news:consnu$sg1$1@www.eclipse.org...
> > > Hi All,
> > > I have created my own widget that contains a table control. The
problem
> I
> > > am
> > > currently having is the widget only takes up 1 horizontal span of the
> > > composite. My example contains one row of a label and text control
> > > followed
> > > below by my widget. Directly using a table control instead of my
widget
> > > works fine.
> > > I would appreciate any ideas/help.
> > >
> > > public MyExample(Composite parent) {
> > >
> > > setLayout(parent);
> > > addControls(parent);
> > > }
> > >
> > > private void setLayout(Composite composite) {
> > >
> > > // Create a composite to hold the children
> > > composite.setLayoutData(new GridData(GridData.FILL_BOTH));
> > >
> > > // Set numColumns for the buttons
> > > int numColumns = 2;
> > > GridLayout layout = new GridLayout(numColumns, false);
> > > layout.marginWidth = 4;
> > > composite.setLayout (layout);
> > > }
> > >
> > >
> > > public void addControls(Composite container) {
> > >
> > > Label label = new Label(container, SWT.NONE);
> > > label.setText("Testing");
> > >
> > > // create text control
> > > Text control = new Text(container, SWT.BORDER | SWT.SINGLE);
> > > final GridData gridData = new GridData(GridData.FILL_HORIZONTAL |
> > > GridData.VERTICAL_ALIGN_END);
> > > gridData.horizontalSpan = 2;
> > > control.setLayoutData(gridData);
> > >
> > > // create my widget
> > > int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL |
> > > SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
> > >
> > > MyTableWidget widget = new MyTableWidget(parent, style);
> > >
> > >
> > > }
> > >
> > > public MyTableWidget(Composite parent, int style) {
> > >
> > > super(parent, SWT.NONE);
> > >
> > > // Set GridLayout
> > > int numColumns = 4; // default;
> > > Layout data = (Layout) parent.getLayout();
> > > if (data instanceof GridLayout) {
> > > numColumns = ((GridLayout) data).numColumns;
> > > }
> > >
> > > GridLayout layout = new GridLayout(numColumns, false);
> > > setLayout(layout);
> > >
> > > // Set composite layout
> > > GridData gridData = new GridData(GridData.FILL_BOTH);
> > > //setLayoutData(gridData);
> > >
> > > table = new Table(this, style);
> > >
> > > // Set table layout
> > > gridData.horizontalSpan = numColumns;
> > > table.setLayoutData(gridData);
> > >
> > > // Show lines and header
> > > table.setLinesVisible(true);
> > > table.setHeaderVisible(true);
> > > }
> > >
> > >
> > >
> >
> >
>
>
|
|
|
Goto Forum:
Current Time: Tue Apr 23 16:05:33 GMT 2024
Powered by FUDForum. Page generated in 0.03594 seconds
|