Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Setting the widget size while using GridLayout
Setting the widget size while using GridLayout [message #442546] Tue, 07 September 2004 15:42 Go to next message
Eclipse UserFriend
Originally posted by: kevin.clark.accessbc.com.nospam

Hi,

I'm making a subclass of the JFace dialog. The dialog requires that I use
GridLayout to set up the dialog area. For some reason though, I am unable
to set the size of my widgets. It's extremely frustrating. I'm used to
designing with FormLayout, and have never run into this problem.

I'm likely overlooking something small (or perhaps it's just inexperience
with GridLayout). But I'd like to know how I can set the size of each of
my widgets.

The code sample below illustrates what I'm doing:

protected Control createDialogArea(Composite parent){

Composite comp = new Composite(parent, SWT.NONE);

// Create a new layout using GridLayout
GridLayout layout = new GridLayout();
layout.numColumns = 4;
layout.marginHeight = 3;
layout.marginWidth = 3;
layout.verticalSpacing = 5;
comp.setLayout(layout);

Label lAmount = new Label(comp, SWT.WRAP);
lAmount.setText("Amount:");
GridData data = new GridData();
data.horizontalSpan = 2;
data.horizontalIndent = 10;
lAmount.setLayoutData(data);

Label lDescription = new Label(comp, SWT.WRAP);
lDescription.setText("Description:");
data = new GridData();
data.horizontalSpan = 2;
lDescription.setLayoutData(data);

//Row two

Label lDollar = new Label(comp, SWT.WRAP | SWT.RIGHT);
lDollar.setText("$");
//This line has no effect on the widget at all.
lDollar.setSize(50, SWT.DEFAULT);
data = new GridData();
lDollar.setLayoutData(data);

Text _tAmount = new Text(comp, SWT.BORDER | SWT.SINGLE);
//Again, this line has no effect
_tAmount.setSize(60, SWT.DEFAULT);
data = new GridData();
_tAmount.setLayoutData(data);

//One more widget that spans two columns, and then another couple rows

//Return this Composite
return comp;
}


The dialog box won't be resized or anything, so I don't have a problem
with hardcoding width and height. Can anyone tell me how to set the size
of my widgets (since widget.setSize(width, height) doesn't work in this
case)? Or alternatively, could anyone tell me how to set the size of each
column?

Thank you,
Kevin
Re: Setting the widget size while using GridLayout [message #442551 is a reply to message #442546] Tue, 07 September 2004 17:04 Go to previous messageGo to next message
Eclipse UserFriend
Hi, Kevin.

Don't use setSize() on the widget. Instead, set the widthHint/heightHint
fields of the GridData.

Carolyn

"Kevbo" <kevin.clark@accessbc.com.nospam> wrote in message
news:chl2ud$a6b$1@eclipse.org...
> Hi,
>
> I'm making a subclass of the JFace dialog. The dialog requires that I use
> GridLayout to set up the dialog area. For some reason though, I am unable
> to set the size of my widgets. It's extremely frustrating. I'm used to
> designing with FormLayout, and have never run into this problem.
>
> I'm likely overlooking something small (or perhaps it's just inexperience
> with GridLayout). But I'd like to know how I can set the size of each of
> my widgets.
>
> The code sample below illustrates what I'm doing:
>
> protected Control createDialogArea(Composite parent){
>
> Composite comp = new Composite(parent, SWT.NONE);
>
> // Create a new layout using GridLayout
> GridLayout layout = new GridLayout();
> layout.numColumns = 4;
> layout.marginHeight = 3;
> layout.marginWidth = 3;
> layout.verticalSpacing = 5;
> comp.setLayout(layout);
>
> Label lAmount = new Label(comp, SWT.WRAP);
> lAmount.setText("Amount:");
> GridData data = new GridData();
> data.horizontalSpan = 2;
> data.horizontalIndent = 10;
> lAmount.setLayoutData(data);
>
> Label lDescription = new Label(comp, SWT.WRAP);
> lDescription.setText("Description:");
> data = new GridData();
> data.horizontalSpan = 2;
> lDescription.setLayoutData(data);
>
> //Row two
>
> Label lDollar = new Label(comp, SWT.WRAP | SWT.RIGHT);
> lDollar.setText("$");
> //This line has no effect on the widget at all.
> lDollar.setSize(50, SWT.DEFAULT);
> data = new GridData();
> lDollar.setLayoutData(data);
>
> Text _tAmount = new Text(comp, SWT.BORDER | SWT.SINGLE);
> //Again, this line has no effect
> _tAmount.setSize(60, SWT.DEFAULT);
> data = new GridData();
> _tAmount.setLayoutData(data);
>
> //One more widget that spans two columns, and then another couple rows
>
> //Return this Composite
> return comp;
> }
>
>
> The dialog box won't be resized or anything, so I don't have a problem
> with hardcoding width and height. Can anyone tell me how to set the size
> of my widgets (since widget.setSize(width, height) doesn't work in this
> case)? Or alternatively, could anyone tell me how to set the size of each
> column?
>
> Thank you,
> Kevin
>
Re: Setting the widget size while using GridLayout [message #442553 is a reply to message #442546] Tue, 07 September 2004 19:28 Go to previous message
Eclipse UserFriend
You try :
GridData data = new GridData();
data.widthHint = 50;
data.heightHint=20;
widget.setLayoutData(data);

regards
Kevbo wrote:

> Hi,
>
> I'm making a subclass of the JFace dialog. The dialog requires that I use
> GridLayout to set up the dialog area. For some reason though, I am unable
> to set the size of my widgets. It's extremely frustrating. I'm used to
> designing with FormLayout, and have never run into this problem.
>
> I'm likely overlooking something small (or perhaps it's just inexperience
> with GridLayout). But I'd like to know how I can set the size of each of
> my widgets.
>
> The code sample below illustrates what I'm doing:
>
> protected Control createDialogArea(Composite parent){
>
> Composite comp = new Composite(parent, SWT.NONE);
>
> // Create a new layout using GridLayout
> GridLayout layout = new GridLayout();
> layout.numColumns = 4;
> layout.marginHeight = 3;
> layout.marginWidth = 3;
> layout.verticalSpacing = 5;
> comp.setLayout(layout);
>
> Label lAmount = new Label(comp, SWT.WRAP);
> lAmount.setText("Amount:");
> GridData data = new GridData();
> data.horizontalSpan = 2;
> data.horizontalIndent = 10;
> lAmount.setLayoutData(data);
>
> Label lDescription = new Label(comp, SWT.WRAP);
> lDescription.setText("Description:");
> data = new GridData();
> data.horizontalSpan = 2;
> lDescription.setLayoutData(data);
>
> //Row two
>
> Label lDollar = new Label(comp, SWT.WRAP | SWT.RIGHT);
> lDollar.setText("$");
> //This line has no effect on the widget at all.
> lDollar.setSize(50, SWT.DEFAULT);
> data = new GridData();
> lDollar.setLayoutData(data);
>
> Text _tAmount = new Text(comp, SWT.BORDER | SWT.SINGLE);
> //Again, this line has no effect
> _tAmount.setSize(60, SWT.DEFAULT);
> data = new GridData();
> _tAmount.setLayoutData(data);
>
> //One more widget that spans two columns, and then another couple rows
>
> //Return this Composite
> return comp;
> }
>
>
> The dialog box won't be resized or anything, so I don't have a problem
> with hardcoding width and height. Can anyone tell me how to set the size
> of my widgets (since widget.setSize(width, height) doesn't work in this
> case)? Or alternatively, could anyone tell me how to set the size of each
> column?
>
> Thank you,
> Kevin
Re: Setting the widget size while using GridLayout [message #442556 is a reply to message #442551] Tue, 07 September 2004 17:32 Go to previous message
Eclipse UserFriend
Originally posted by: kevin.clark.accessbc.com.nospam

Carolyn,

Thank you for the tip! It works as I want it to now. =)

Kevin


Carolyn MacLeod wrote:

> Hi, Kevin.

> Don't use setSize() on the widget. Instead, set the widthHint/heightHint
> fields of the GridData.

> Carolyn

> "Kevbo" <kevin.clark@accessbc.com.nospam> wrote in message
> news:chl2ud$a6b$1@eclipse.org...
> > Hi,
> >
> > I'm making a subclass of the JFace dialog. The dialog requires that I use
> > GridLayout to set up the dialog area. For some reason though, I am unable
> > to set the size of my widgets. It's extremely frustrating. I'm used to
> > designing with FormLayout, and have never run into this problem.
> >
> > I'm likely overlooking something small (or perhaps it's just inexperience
> > with GridLayout). But I'd like to know how I can set the size of each of
> > my widgets.
> >
> > The code sample below illustrates what I'm doing:
> >
> > protected Control createDialogArea(Composite parent){
> >
> > Composite comp = new Composite(parent, SWT.NONE);
> >
> > // Create a new layout using GridLayout
> > GridLayout layout = new GridLayout();
> > layout.numColumns = 4;
> > layout.marginHeight = 3;
> > layout.marginWidth = 3;
> > layout.verticalSpacing = 5;
> > comp.setLayout(layout);
> >
> > Label lAmount = new Label(comp, SWT.WRAP);
> > lAmount.setText("Amount:");
> > GridData data = new GridData();
> > data.horizontalSpan = 2;
> > data.horizontalIndent = 10;
> > lAmount.setLayoutData(data);
> >
> > Label lDescription = new Label(comp, SWT.WRAP);
> > lDescription.setText("Description:");
> > data = new GridData();
> > data.horizontalSpan = 2;
> > lDescription.setLayoutData(data);
> >
> > //Row two
> >
> > Label lDollar = new Label(comp, SWT.WRAP | SWT.RIGHT);
> > lDollar.setText("$");
> > //This line has no effect on the widget at all.
> > lDollar.setSize(50, SWT.DEFAULT);
> > data = new GridData();
> > lDollar.setLayoutData(data);
> >
> > Text _tAmount = new Text(comp, SWT.BORDER | SWT.SINGLE);
> > //Again, this line has no effect
> > _tAmount.setSize(60, SWT.DEFAULT);
> > data = new GridData();
> > _tAmount.setLayoutData(data);
> >
> > //One more widget that spans two columns, and then another couple rows
> >
> > //Return this Composite
> > return comp;
> > }
> >
> >
> > The dialog box won't be resized or anything, so I don't have a problem
> > with hardcoding width and height. Can anyone tell me how to set the size
> > of my widgets (since widget.setSize(width, height) doesn't work in this
> > case)? Or alternatively, could anyone tell me how to set the size of each
> > column?
> >
> > Thank you,
> > Kevin
> >
Re: Setting the widget size while using GridLayout [message #442557 is a reply to message #442553] Tue, 07 September 2004 17:32 Go to previous message
Eclipse UserFriend
Originally posted by: kevin.clark.accessbc.com.nospam

I did try and it works. Thank you for your help!

Kevin


snpe wrote:

> You try :
> GridData data = new GridData();
> data.widthHint = 50;
> data.heightHint=20;
> widget.setLayoutData(data);

> regards
> Kevbo wrote:

> > Hi,
> >
> > I'm making a subclass of the JFace dialog. The dialog requires that I use
> > GridLayout to set up the dialog area. For some reason though, I am unable
> > to set the size of my widgets. It's extremely frustrating. I'm used to
> > designing with FormLayout, and have never run into this problem.
> >
> > I'm likely overlooking something small (or perhaps it's just inexperience
> > with GridLayout). But I'd like to know how I can set the size of each of
> > my widgets.
> >
> > The code sample below illustrates what I'm doing:
> >
> > protected Control createDialogArea(Composite parent){
> >
> > Composite comp = new Composite(parent, SWT.NONE);
> >
> > // Create a new layout using GridLayout
> > GridLayout layout = new GridLayout();
> > layout.numColumns = 4;
> > layout.marginHeight = 3;
> > layout.marginWidth = 3;
> > layout.verticalSpacing = 5;
> > comp.setLayout(layout);
> >
> > Label lAmount = new Label(comp, SWT.WRAP);
> > lAmount.setText("Amount:");
> > GridData data = new GridData();
> > data.horizontalSpan = 2;
> > data.horizontalIndent = 10;
> > lAmount.setLayoutData(data);
> >
> > Label lDescription = new Label(comp, SWT.WRAP);
> > lDescription.setText("Description:");
> > data = new GridData();
> > data.horizontalSpan = 2;
> > lDescription.setLayoutData(data);
> >
> > //Row two
> >
> > Label lDollar = new Label(comp, SWT.WRAP | SWT.RIGHT);
> > lDollar.setText("$");
> > //This line has no effect on the widget at all.
> > lDollar.setSize(50, SWT.DEFAULT);
> > data = new GridData();
> > lDollar.setLayoutData(data);
> >
> > Text _tAmount = new Text(comp, SWT.BORDER | SWT.SINGLE);
> > //Again, this line has no effect
> > _tAmount.setSize(60, SWT.DEFAULT);
> > data = new GridData();
> > _tAmount.setLayoutData(data);
> >
> > //One more widget that spans two columns, and then another couple rows
> >
> > //Return this Composite
> > return comp;
> > }
> >
> >
> > The dialog box won't be resized or anything, so I don't have a problem
> > with hardcoding width and height. Can anyone tell me how to set the size
> > of my widgets (since widget.setSize(width, height) doesn't work in this
> > case)? Or alternatively, could anyone tell me how to set the size of each
> > column?
> >
> > Thank you,
> > Kevin
Previous Topic:transparent pngs in 3.0?
Next Topic:Is a restricted minimum size of a shell possible ?
Goto Forum:
  


Current Time: Tue Jul 08 19:06:12 EDT 2025

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

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

Back to the top