Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » How to Center a Button
How to Center a Button [message #26999] Wed, 23 May 2007 14:24 Go to next message
Roberto Sanchez is currently offline Roberto SanchezFriend
Messages: 82
Registered: July 2009
Member
Hi, I'm not able to center a Button widget in a Composite, I know that
my problem sounds easy to solve, but I can't see the problem:


My code:

Composite comp = new Composite(parent, SWT.BORDER);
GridData gdata = new GridData(SWT.CENTER, SWT.DEFAULT, false, false);
gdata.widthHint = parent.getShell().getSize().x - 4;
comp.setLayoutData(data);

GridLayout gridLayout = new GridLayout(1, true);
comp.setLayout(gridLayout);

gdata = new GridData(SWT.CENTER, SWT.DEFAULT, false, false);
gdata.heightHint = 22;
gdata.widthHint = 90;


final Button loginButton = new Button( comp, SWT.PUSH | SWT.FLAT);
loginButton.setText( "OK" );
loginButton.setImage(Iconos.ICO_OK);
loginButton.setLayoutData(gdata);


Does anyone see what I'm doing wrong ?

Thanks in advance.
Roberto.
Re: How to Center a Button [message #27039 is a reply to message #26999] Wed, 23 May 2007 19:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rsternberg.innoopract.com

Hi Roberto,

I guess that your button is well centered within the cell, but the cell
is just as wide as the button. Try to change the line

> gdata = new GridData(SWT.CENTER, SWT.DEFAULT, false, false);

into

gdata = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);

This lets the column of the GridLayout grow to the available horizontal
width.

If this doesn't help, make sure that the Composite comp is as large as
you expect it to be, e.g. by setting a background color on it.

Hope that helps,

Ralf
Re: How to Center a Button [message #27118 is a reply to message #27039] Thu, 24 May 2007 07:55 Go to previous message
Roberto Sanchez is currently offline Roberto SanchezFriend
Messages: 82
Registered: July 2009
Member
OK, now it works, I was confused about grabExcessHorizontalSpace
behaviour, I though that It affects to cell content, but in fact, It
only affects to cell itself, not to the content.

Thank you and I'm sorry for this so basic question ;-)
Roberto.


Ralf Sternberg escribió:
> Hi Roberto,
>
> I guess that your button is well centered within the cell, but the cell
> is just as wide as the button. Try to change the line
>
>> gdata = new GridData(SWT.CENTER, SWT.DEFAULT, false, false);
>
> into
>
> gdata = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
>
> This lets the column of the GridLayout grow to the available horizontal
> width.
>
> If this doesn't help, make sure that the Composite comp is as large as
> you expect it to be, e.g. by setting a background color on it.
>
> Hope that helps,
>
> Ralf
Previous Topic:Closing Dialog with ESC key
Next Topic:MessageBox
Goto Forum:
  


Current Time: Fri Apr 26 00:48:34 GMT 2024

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

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

Back to the top