Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » GridLayout: can I have an empty cell in the grid?
GridLayout: can I have an empty cell in the grid? [message #447403] Tue, 14 December 2004 10:11 Go to next message
Liam Morley is currently offline Liam MorleyFriend
Messages: 47
Registered: July 2009
Member
I'd like to lay something out like this:

First Label: [ First Text ]
Second Label: [ Second Text ] {Button}

but "Second Label" is showing up on the top row. The only ways I can
think of to get around this are (a) to insert an invisible composite on
row 1 which is the same size as the button on row 2, or (b) use Form
layout. I think it'd be much easier, however, if I could just "skip" a
cell, or tell "second label" to start on a new row. Is this possible
with GridLayout?


--
Liam Morley
Computer Science Undergraduate
Worcester Polytechnic Institute
Re: GridLayout: can I have an empty cell in the grid? [message #447409 is a reply to message #447403] Tue, 14 December 2004 14:10 Go to previous messageGo to next message
Florian Georg is currently offline Florian GeorgFriend
Messages: 22
Registered: July 2009
Junior Member
Try something like:

========[snip]===========
// GridLayout on yout "parent" composite
composite.setLayout(new GridLayout(3,false));

// First Label
Label firstLabel = new Label (composite,SWT.NONE);

// First Text, spanning two cells horizontally and grabbing
Text firstText = new Text (composite,SWT.BORDER);
GridData gd = new GridData(GridData.GRAB_HORIZONTAL);
gd.horizontalSpan = 2;
firstText.setLayoutData(gd);

//Second Label
Label secondLabel = new Label (composite,SWT.NONE);

// Second Text
Text secondText = new Text (composite,SWT.BORDER);

// The Button
Button button = new Button (composite,SWT.BORDER);
========[snip]===========

This was hacked freely from mind, so it may not compile when copy &
paste - but I think it should almost ;-)

regards
Florian

Liam Morley wrote:

> I'd like to lay something out like this:
>
> First Label: [ First Text ]
> Second Label: [ Second Text ] {Button}
>
> but "Second Label" is showing up on the top row. The only ways I can
> think of to get around this are (a) to insert an invisible composite on
> row 1 which is the same size as the button on row 2, or (b) use Form
> layout. I think it'd be much easier, however, if I could just "skip" a
> cell, or tell "second label" to start on a new row. Is this possible
> with GridLayout?
>
>
Re: GridLayout: can I have an empty cell in the grid? [message #447570 is a reply to message #447409] Tue, 14 December 2004 23:02 Go to previous messageGo to next message
Liam Morley is currently offline Liam MorleyFriend
Messages: 47
Registered: July 2009
Member
Thanks for the reply. The only thing is (and I didn't specify this
explicitly in the first e-mail, I'm sorry), I only want the firstText to
take up one cell (so as to be the same size as the text below it). In
the snip below, firstText would take up the rest of the row. While this
would make secondLabel start on the second row (which is what I want),
I'm looking for a solution which keeps both text fields the same size.



Florian Georg wrote:
> Try something like:
>
> ========[snip]===========
> // GridLayout on yout "parent" composite
> composite.setLayout(new GridLayout(3,false));
>
> // First Label
> Label firstLabel = new Label (composite,SWT.NONE);
>
> // First Text, spanning two cells horizontally and grabbing
> Text firstText = new Text (composite,SWT.BORDER);
> GridData gd = new GridData(GridData.GRAB_HORIZONTAL);
> gd.horizontalSpan = 2;
> firstText.setLayoutData(gd);
>
> //Second Label
> Label secondLabel = new Label (composite,SWT.NONE);
>
> // Second Text
> Text secondText = new Text (composite,SWT.BORDER);
>
> // The Button
> Button button = new Button (composite,SWT.BORDER);
> ========[snip]===========
>
> This was hacked freely from mind, so it may not compile when copy &
> paste - but I think it should almost ;-)
>
> regards
> Florian
>
> Liam Morley wrote:
>
>> I'd like to lay something out like this:
>>
>> First Label: [ First Text ]
>> Second Label: [ Second Text ] {Button}
>>
>> but "Second Label" is showing up on the top row. The only ways I can
>> think of to get around this are (a) to insert an invisible composite
>> on row 1 which is the same size as the button on row 2, or (b) use
>> Form layout. I think it'd be much easier, however, if I could just
>> "skip" a cell, or tell "second label" to start on a new row. Is this
>> possible with GridLayout?
>>
>>


--
Liam Morley
Computer Science Undergraduate
Worcester Polytechnic Institute
Re: GridLayout: can I have an empty cell in the grid? [message #447571 is a reply to message #447570] Tue, 14 December 2004 23:43 Go to previous messageGo to next message
Daniel Spiewak is currently offline Daniel SpiewakFriend
Messages: 263
Registered: July 2009
Senior Member
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="serif">I've always used an empty label as a spacer.&nbsp; Simply
use:<br>
<br>
new Label(composite, SWT.NONE).setText("");<br>
<br>
This will take up one cell of your layout, without actually displaying
anything.<br>
<br>
Daniel<br>
</font><br>
Liam Morley wrote:
<blockquote cite="midcpnrek$997$1@www.eclipse.org" type="cite">Thanks
for the reply. The only thing is (and I didn't specify this explicitly
in the first e-mail, I'm sorry), I only want the firstText to take up
one cell (so as to be the same size as the text below it). In the snip
below, firstText would take up the rest of the row. While this would
make secondLabel start on the second row (which is what I want), I'm
looking for a solution which keeps both text fields the same size.
<br>
<br>
<br>
<br>
Florian Georg wrote:
<br>
<blockquote type="cite">Try something like:
<br>
<br>
========[snip]===========
<br>
// GridLayout on yout "parent" composite
<br>
composite.setLayout(new GridLayout(3,false));
<br>
<br>
// First Label
<br>
Label firstLabel = new Label (composite,SWT.NONE);
<br>
<br>
// First Text, spanning two cells horizontally and grabbing
<br>
Text firstText = new Text (composite,SWT.BORDER);
<br>
GridData gd = new GridData(GridData.GRAB_HORIZONTAL);
<br>
gd.horizontalSpan = 2;
<br>
firstText.setLayoutData(gd);
<br>
<br>
//Second Label
<br>
Label secondLabel = new Label (composite,SWT.NONE);
<br>
<br>
// Second Text
<br>
Text secondText = new Text (composite,SWT.BORDER);
<br>
<br>
// The Button
<br>
Button button = new Button (composite,SWT.BORDER);
<br>
========[snip]===========
<br>
<br>
This was hacked freely from mind, so it may not compile when copy &amp;
paste - but I think it should almost ;-)
<br>
<br>
regards
<br>
&nbsp; Florian
<br>
<br>
Liam Morley wrote:
<br>
<br>
<blockquote type="cite">I'd like to lay something out like this:
<br>
<br>
First Label:&nbsp;&nbsp; [ First Text&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]
<br>
Second Label:&nbsp; [ Second Text&nbsp;&nbsp;&nbsp;&nbsp; ] {Button}
<br>
<br>
but "Second Label" is showing up on the top row. The only ways I can
think of to get around this are (a) to insert an invisible composite on
row 1 which is the same size as the button on row 2, or (b) use Form
layout. I think it'd be much easier, however, if I could just "skip" a
cell, or tell "second label" to start on a new row. Is this possible
with GridLayout?
<br>
<br>
<br>
</blockquote>
</blockquote>
<br>
<br>
</blockquote>
</body>
</html>
Re: GridLayout: can I have an empty cell in the grid? [message #447573 is a reply to message #447571] Tue, 14 December 2004 23:59 Go to previous messageGo to next message
Paul Singleton is currently offline Paul SingletonFriend
Messages: 37
Registered: July 2009
Member
Daniel Spiewak wrote:
> I've always used an empty label as a spacer. Simply use:
>
> new Label(composite, SWT.NONE).setText("");

Hmm, zero width I guess but the height of the default font?

Maybe we need a custom no-op control? :-)

Paul S.

> This will take up one cell of your layout, without actually displaying
> anything.
>
> Daniel
>
> Liam Morley wrote:
>
>> Thanks for the reply. The only thing is (and I didn't specify this
>> explicitly in the first e-mail, I'm sorry), I only want the firstText
>> to take up one cell (so as to be the same size as the text below it).
>> In the snip below, firstText would take up the rest of the row. While
>> this would make secondLabel start on the second row (which is what I
>> want), I'm looking for a solution which keeps both text fields the
>> same size.
>>
>>
>>
>> Florian Georg wrote:
>>
>>> Try something like:
>>>
>>> ========[snip]===========
>>> // GridLayout on yout "parent" composite
>>> composite.setLayout(new GridLayout(3,false));
>>>
>>> // First Label
>>> Label firstLabel = new Label (composite,SWT.NONE);
>>>
>>> // First Text, spanning two cells horizontally and grabbing
>>> Text firstText = new Text (composite,SWT.BORDER);
>>> GridData gd = new GridData(GridData.GRAB_HORIZONTAL);
>>> gd.horizontalSpan = 2;
>>> firstText.setLayoutData(gd);
>>>
>>> //Second Label
>>> Label secondLabel = new Label (composite,SWT.NONE);
>>>
>>> // Second Text
>>> Text secondText = new Text (composite,SWT.BORDER);
>>>
>>> // The Button
>>> Button button = new Button (composite,SWT.BORDER);
>>> ========[snip]===========
>>>
>>> This was hacked freely from mind, so it may not compile when copy &
>>> paste - but I think it should almost ;-)
>>>
>>> regards
>>> Florian
>>>
>>> Liam Morley wrote:
>>>
>>>> I'd like to lay something out like this:
>>>>
>>>> First Label: [ First Text ]
>>>> Second Label: [ Second Text ] {Button}
>>>>
>>>> but "Second Label" is showing up on the top row. The only ways I can
>>>> think of to get around this are (a) to insert an invisible composite
>>>> on row 1 which is the same size as the button on row 2, or (b) use
>>>> Form layout. I think it'd be much easier, however, if I could just
>>>> "skip" a cell, or tell "second label" to start on a new row. Is this
>>>> possible with GridLayout?
>>>>
>>>>
>>
>>
Re: GridLayout: can I have an empty cell in the grid? [message #447577 is a reply to message #447573] Wed, 15 December 2004 00:51 Go to previous messageGo to next message
Mani Ghamari is currently offline Mani GhamariFriend
Messages: 33
Registered: July 2009
Member
Maybe the same effect can be achieved with FormLayout without actually
inserting an empty Label or Composite?

Yet, I think using GridLayout and an empty Label/Composite is a much
painless process and the performace
drawbacks are neglectable.

btw, I think the label is a better solution because it directly extends
Control and there are no layout managers involved.
(Composite extends Scrollable, which, I suppose, might require more
instructions/method calls for a redraw than a label with no text)

maybe using Control.setCapture(false) on the empty control would even
further minimize the performance drawback?

Anyways, I have always used this technique and it has always work out for me
:-)

regards,

Mani

"Paul Singleton" <paul@jbgb.com> wrote in message
news:cpnupf$hs2$1@www.eclipse.org...
> Daniel Spiewak wrote:
>> I've always used an empty label as a spacer. Simply use:
>>
>> new Label(composite, SWT.NONE).setText("");
>
> Hmm, zero width I guess but the height of the default font?
>
> Maybe we need a custom no-op control? :-)
>
> Paul S.
>
>> This will take up one cell of your layout, without actually displaying
>> anything.
>>
>> Daniel
>>
>> Liam Morley wrote:
>>
>>> Thanks for the reply. The only thing is (and I didn't specify this
>>> explicitly in the first e-mail, I'm sorry), I only want the firstText to
>>> take up one cell (so as to be the same size as the text below it). In
>>> the snip below, firstText would take up the rest of the row. While this
>>> would make secondLabel start on the second row (which is what I want),
>>> I'm looking for a solution which keeps both text fields the same size.
>>>
>>>
>>>
>>> Florian Georg wrote:
>>>
>>>> Try something like:
>>>>
>>>> ========[snip]===========
>>>> // GridLayout on yout "parent" composite
>>>> composite.setLayout(new GridLayout(3,false));
>>>>
>>>> // First Label
>>>> Label firstLabel = new Label (composite,SWT.NONE);
>>>>
>>>> // First Text, spanning two cells horizontally and grabbing
>>>> Text firstText = new Text (composite,SWT.BORDER);
>>>> GridData gd = new GridData(GridData.GRAB_HORIZONTAL);
>>>> gd.horizontalSpan = 2;
>>>> firstText.setLayoutData(gd);
>>>>
>>>> //Second Label
>>>> Label secondLabel = new Label (composite,SWT.NONE);
>>>>
>>>> // Second Text
>>>> Text secondText = new Text (composite,SWT.BORDER);
>>>>
>>>> // The Button
>>>> Button button = new Button (composite,SWT.BORDER);
>>>> ========[snip]===========
>>>>
>>>> This was hacked freely from mind, so it may not compile when copy &
>>>> paste - but I think it should almost ;-)
>>>>
>>>> regards
>>>> Florian
>>>>
>>>> Liam Morley wrote:
>>>>
>>>>> I'd like to lay something out like this:
>>>>>
>>>>> First Label: [ First Text ]
>>>>> Second Label: [ Second Text ] {Button}
>>>>>
>>>>> but "Second Label" is showing up on the top row. The only ways I can
>>>>> think of to get around this are (a) to insert an invisible composite
>>>>> on row 1 which is the same size as the button on row 2, or (b) use
>>>>> Form layout. I think it'd be much easier, however, if I could just
>>>>> "skip" a cell, or tell "second label" to start on a new row. Is this
>>>>> possible with GridLayout?
>>>>>
>>>>>
>>>
>>>
Re: GridLayout: can I have an empty cell in the grid? [message #447579 is a reply to message #447577] Wed, 15 December 2004 03:14 Go to previous messageGo to next message
Liam Morley is currently offline Liam MorleyFriend
Messages: 47
Registered: July 2009
Member
Thanks, I was using a button before (I'll switch to a label) but I
wasn't sure if that was 'kosher' or not. I was curious about the
performance issues and whether it would be worth it to switch to
FormLayout, but I think don't think it is.

Thanks for the tip on setCapture(false), I'll use that as well.



Mani Ghamari wrote:
> Maybe the same effect can be achieved with FormLayout without actually
> inserting an empty Label or Composite?
>
> Yet, I think using GridLayout and an empty Label/Composite is a much
> painless process and the performace
> drawbacks are neglectable.
>
> btw, I think the label is a better solution because it directly extends
> Control and there are no layout managers involved.
> (Composite extends Scrollable, which, I suppose, might require more
> instructions/method calls for a redraw than a label with no text)
>
> maybe using Control.setCapture(false) on the empty control would even
> further minimize the performance drawback?
>
> Anyways, I have always used this technique and it has always work out for me
> :-)
>
> regards,
>
> Mani
>
> "Paul Singleton" <paul@jbgb.com> wrote in message
> news:cpnupf$hs2$1@www.eclipse.org...
>
>>Daniel Spiewak wrote:
>>
>>>I've always used an empty label as a spacer. Simply use:
>>>
>>>new Label(composite, SWT.NONE).setText("");
>>
>>Hmm, zero width I guess but the height of the default font?
>>
>>Maybe we need a custom no-op control? :-)
>>
>>Paul S.
>>
>>
>>>This will take up one cell of your layout, without actually displaying
>>>anything.
>>>
>>>Daniel
>>>
>>>Liam Morley wrote:
>>>
>>>
>>>>Thanks for the reply. The only thing is (and I didn't specify this
>>>>explicitly in the first e-mail, I'm sorry), I only want the firstText to
>>>>take up one cell (so as to be the same size as the text below it). In
>>>>the snip below, firstText would take up the rest of the row. While this
>>>>would make secondLabel start on the second row (which is what I want),
>>>>I'm looking for a solution which keeps both text fields the same size.
>>>>
>>>>
>>>>
>>>>Florian Georg wrote:
>>>>
>>>>
>>>>>Try something like:
>>>>>
>>>>>========[snip]===========
>>>>>// GridLayout on yout "parent" composite
>>>>>composite.setLayout(new GridLayout(3,false));
>>>>>
>>>>>// First Label
>>>>>Label firstLabel = new Label (composite,SWT.NONE);
>>>>>
>>>>>// First Text, spanning two cells horizontally and grabbing
>>>>>Text firstText = new Text (composite,SWT.BORDER);
>>>>>GridData gd = new GridData(GridData.GRAB_HORIZONTAL);
>>>>>gd.horizontalSpan = 2;
>>>>>firstText.setLayoutData(gd);
>>>>>
>>>>>//Second Label
>>>>>Label secondLabel = new Label (composite,SWT.NONE);
>>>>>
>>>>>// Second Text
>>>>>Text secondText = new Text (composite,SWT.BORDER);
>>>>>
>>>>>// The Button
>>>>>Button button = new Button (composite,SWT.BORDER);
>>>>>========[snip]===========
>>>>>
>>>>>This was hacked freely from mind, so it may not compile when copy &
>>>>>paste - but I think it should almost ;-)
>>>>>
>>>>>regards
>>>>> Florian
>>>>>
>>>>>Liam Morley wrote:
>>>>>
>>>>>
>>>>>>I'd like to lay something out like this:
>>>>>>
>>>>>>First Label: [ First Text ]
>>>>>>Second Label: [ Second Text ] {Button}
>>>>>>
>>>>>>but "Second Label" is showing up on the top row. The only ways I can
>>>>>>think of to get around this are (a) to insert an invisible composite
>>>>>>on row 1 which is the same size as the button on row 2, or (b) use
>>>>>>Form layout. I think it'd be much easier, however, if I could just
>>>>>>"skip" a cell, or tell "second label" to start on a new row. Is this
>>>>>>possible with GridLayout?
>>>>>>
>>>>>>
>>>>
>>>>
>
>


--
Liam Morley
Computer Science Undergraduate
Worcester Polytechnic Institute
Re: GridLayout: can I have an empty cell in the grid? [message #447754 is a reply to message #447579] Fri, 17 December 2004 13:23 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Use Label - it does not take focus and will not be part of the tab traversal
sequence. You can even make it invisible (Label.setVisible(false) to make
sure it does not have any strange drawing effects (such as a solid
background over a striped parent).

DO NOT use setCapture(false). This API is only intended to be used by
people writing their own widgets who need to maintain control of the Mouse
events for a certain short period of time. Do not use it without fully
understanding the implications. In your case, it will not help you at all.

"Liam Morley" <lmorley@wpi.edu> wrote in message
news:cpoa64$g88$1@www.eclipse.org...
> Thanks, I was using a button before (I'll switch to a label) but I wasn't
> sure if that was 'kosher' or not. I was curious about the performance
> issues and whether it would be worth it to switch to FormLayout, but I
> think don't think it is.
>
> Thanks for the tip on setCapture(false), I'll use that as well.
>
>
>
> Mani Ghamari wrote:
>> Maybe the same effect can be achieved with FormLayout without actually
>> inserting an empty Label or Composite?
>>
>> Yet, I think using GridLayout and an empty Label/Composite is a much
>> painless process and the performace
>> drawbacks are neglectable.
>>
>> btw, I think the label is a better solution because it directly extends
>> Control and there are no layout managers involved.
>> (Composite extends Scrollable, which, I suppose, might require more
>> instructions/method calls for a redraw than a label with no text)
>>
>> maybe using Control.setCapture(false) on the empty control would even
>> further minimize the performance drawback?
>>
>> Anyways, I have always used this technique and it has always work out for
>> me :-)
>>
>> regards,
>>
>> Mani
>>
>> "Paul Singleton" <paul@jbgb.com> wrote in message
>> news:cpnupf$hs2$1@www.eclipse.org...
>>
>>>Daniel Spiewak wrote:
>>>
>>>>I've always used an empty label as a spacer. Simply use:
>>>>
>>>>new Label(composite, SWT.NONE).setText("");
>>>
>>>Hmm, zero width I guess but the height of the default font?
>>>
>>>Maybe we need a custom no-op control? :-)
>>>
>>>Paul S.
>>>
>>>
>>>>This will take up one cell of your layout, without actually displaying
>>>>anything.
>>>>
>>>>Daniel
>>>>
>>>>Liam Morley wrote:
>>>>
>>>>
>>>>>Thanks for the reply. The only thing is (and I didn't specify this
>>>>>explicitly in the first e-mail, I'm sorry), I only want the firstText
>>>>>to take up one cell (so as to be the same size as the text below it).
>>>>>In the snip below, firstText would take up the rest of the row. While
>>>>>this would make secondLabel start on the second row (which is what I
>>>>>want), I'm looking for a solution which keeps both text fields the same
>>>>>size.
>>>>>
>>>>>
>>>>>
>>>>>Florian Georg wrote:
>>>>>
>>>>>
>>>>>>Try something like:
>>>>>>
>>>>>>========[snip]===========
>>>>>>// GridLayout on yout "parent" composite
>>>>>>composite.setLayout(new GridLayout(3,false));
>>>>>>
>>>>>>// First Label
>>>>>>Label firstLabel = new Label (composite,SWT.NONE);
>>>>>>
>>>>>>// First Text, spanning two cells horizontally and grabbing
>>>>>>Text firstText = new Text (composite,SWT.BORDER);
>>>>>>GridData gd = new GridData(GridData.GRAB_HORIZONTAL);
>>>>>>gd.horizontalSpan = 2;
>>>>>>firstText.setLayoutData(gd);
>>>>>>
>>>>>>//Second Label
>>>>>>Label secondLabel = new Label (composite,SWT.NONE);
>>>>>>
>>>>>>// Second Text
>>>>>>Text secondText = new Text (composite,SWT.BORDER);
>>>>>>
>>>>>>// The Button
>>>>>>Button button = new Button (composite,SWT.BORDER);
>>>>>>========[snip]===========
>>>>>>
>>>>>>This was hacked freely from mind, so it may not compile when copy &
>>>>>>paste - but I think it should almost ;-)
>>>>>>
>>>>>>regards
>>>>>> Florian
>>>>>>
>>>>>>Liam Morley wrote:
>>>>>>
>>>>>>
>>>>>>>I'd like to lay something out like this:
>>>>>>>
>>>>>>>First Label: [ First Text ]
>>>>>>>Second Label: [ Second Text ] {Button}
>>>>>>>
>>>>>>>but "Second Label" is showing up on the top row. The only ways I can
>>>>>>>think of to get around this are (a) to insert an invisible composite
>>>>>>>on row 1 which is the same size as the button on row 2, or (b) use
>>>>>>>Form layout. I think it'd be much easier, however, if I could just
>>>>>>>"skip" a cell, or tell "second label" to start on a new row. Is this
>>>>>>>possible with GridLayout?
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>
>>
>
>
> --
> Liam Morley
> Computer Science Undergraduate
> Worcester Polytechnic Institute
Previous Topic:Control over SWT Browser Widget ?
Next Topic:Put ico in JFace WizardDialog
Goto Forum:
  


Current Time: Thu Mar 28 16:51:06 GMT 2024

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

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

Back to the top