Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Aligning button text to the left, yet expand button?(Can this be done with GridLayout and GridData?)
Aligning button text to the left, yet expand button? [message #528245] Mon, 19 April 2010 19:37 Go to next message
Herb Miller is currently offline Herb MillerFriend
Messages: 139
Registered: January 2010
Senior Member
I have an application that uses 2 columns of buttons in an Eclipse view. In the createPartControl method, the layout for the parent Composite is left at the default value which turns out to be a horizontal FillLayout. A ScrolledComposite with vertical RowLayout is added to the parent, and a Composite with a 2-column GridLayout is added to the ScrolledComposite. The GridLayout is set to make the columns of equal width.

parent: Composite w/ FillLayout(horizontal)
scroll: ScrolledComposite w/ RowLayout(vertical)
child: Composite w/ GridLayout(2,true)

The buttons are added to the child composite. The problem is that the columns of buttons do not display as equal width. The buttons with less text are shorter, and the buttons with more text are longer.

The only way I was able to get them to be the same width was to use a GridData on each button, and to set the widthHint of the GridData to the same large value on every button. Now the buttons are the same width.

However, the buttons have images and the images and the button text move to the center of the button, and now the images do not line up. Maybe I can show this below:

What I have:
____________________
| Image 1 LargeText1 |
|____________________|

____________________
| Image 2 Text2 |
|____________________|

What I want:
____________________
| Image 1 LargeText1 |
|____________________|

____________________
| Image 2 Text2 |
|____________________|

Notice that in the second case (What I want), the buttons are the same size, but the images and the beginning of the text line up vertically.

Is there any way to achieve the 2nd case?

Thanks.



Re: Aligning button text to the left, yet expand button? [message #528250 is a reply to message #528245] Mon, 19 April 2010 19:42 Go to previous messageGo to next message
Herb Miller is currently offline Herb MillerFriend
Messages: 139
Registered: January 2010
Senior Member
Sorry, but what I typed was not what was sent. Somehow white space was eliminated so both cases look the same.

Maybe this will work. Imagine that the small x's are blanks:


What I have:
____________________
| Image 1xxxxLargeText1xx|
|____________________|

____________________
|xxxxxImage 2 xxText2xxxxxx|
|____________________|

What I want:
____________________
| Image 1xxxxLargeText1xx|
|____________________|

____________________
| Image 2xxxxText2xxxxxxxxx|
|____________________|

Hope this works.
Thanks.

Re: Aligning button text to the left, yet expand button? [message #528395 is a reply to message #528245] Tue, 20 April 2010 11:42 Go to previous messageGo to next message
Praveen  is currently offline Praveen Friend
Messages: 86
Registered: July 2009
Member
I have a few questions regarding the provided layout - since the child
composite is created with GridLayout(2,true)..creating 2 buttons will
align on the same row..
Can you provide us the snippet that would help me to understand the
problem better ?
Re: Aligning button text to the left, yet expand button? [message #528454 is a reply to message #528395] Tue, 20 April 2010 15:12 Go to previous message
Herb Miller is currently offline Herb MillerFriend
Messages: 139
Registered: January 2010
Senior Member
Yes, you are correct. Because of the GridLayout, I do get 2 columns of buttons. That part works well. But the buttons in each column vary their size based on the text.

I would like all of the buttons to be the same size, even if the text value for each button is of different lengths. I set the makeColumnsEqualWidth for the GridLayout to true. But for some reason, the buttons are not the same width. They stll vary their width based on the text.

I was able to get the buttons to be the same width by using a GridData on each button and setting the widthHint.

Using the widthHint did make all of the buttons the same width, but it centered the image attached to the button and it centered the text. I would like to keep the images and text on the left edge of the button.

My diagram (pitiful as it was) was trying to show just 1 column of the buttons, and how the text and images on the button did not line up.

If you need more, please let me know. The code is quite large. If I can pare it down to a small snippet, I will post it.

I am using Galileo on Linux.

Thanks.



Previous Topic:TreeViewer refresh() collapse problem-- SWT
Next Topic:Composite with Canvases doesn't scroll
Goto Forum:
  


Current Time: Thu Mar 28 16:49:24 GMT 2024

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

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

Back to the top