Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Why doesn't grab grab?
Why doesn't grab grab? [message #452199] Tue, 15 March 2005 08:31 Go to next message
Eclipse UserFriend
Originally posted by: bob.objfac.com

Can somebody please explain to me why the tree in this slightly modified
Snippet15 doesn't fill the entire shell?

public class Snipped15Layout {
public static void main(String[] args) {
Display display = new Display ();

Shell shell = new Shell (display);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
shell.setLayout(layout);
Tree tree = new Tree (shell, SWT.BORDER);
GridData data = new GridData(SWT.LEFT, SWT.TOP, true, true);
data.horizontalSpan = 1;
tree.setLayoutData(data);

for (int i=0; i<4; i++) {
TreeItem iItem = new TreeItem (tree, 0);
iItem.setText ("TreeItem (0) -" + i);
for (int j=0; j<4; j++) {
TreeItem jItem = new TreeItem (iItem, 0);
jItem.setText ("TreeItem (1) -" + j);
for (int k=0; k<4; k++) {
TreeItem kItem = new TreeItem (jItem, 0);
kItem.setText ("TreeItem (2) -" + k);
for (int l=0; l<4; l++) {
TreeItem lItem = new TreeItem (kItem, 0);
lItem.setText ("TreeItem (3) -" + l);
}
}
}
}
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}

Thanks!

Bob
Re: Why doesn't grab grab? [message #452205 is a reply to message #452199] Tue, 15 March 2005 13:01 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
It is grabbing, it is just not filling.

You have:

GridData data = new GridData(SWT.LEFT, SWT.TOP, true, true);

which means the cell in the grid will grab any excess vertical or horizontal
space, however, the widget will be aligned in the cell at its top left
corner. If the cell is bigger than the preferred size of the widget, the
widget will be smaller than the cell.

If you change this to

GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);

the cell will grab any excess vertical or horizontal space and the widget
will be stretched (or shrunk as the case may be) to fill the cell
horizontally and vertically.

"Bob Foster" <bob@objfac.com> wrote in message
news:d166go$607$1@www.eclipse.org...
> Can somebody please explain to me why the tree in this slightly modified
> Snippet15 doesn't fill the entire shell?
>
> public class Snipped15Layout {
> public static void main(String[] args) {
> Display display = new Display ();
>
> Shell shell = new Shell (display);
> GridLayout layout = new GridLayout();
> layout.numColumns = 1;
> shell.setLayout(layout);
> Tree tree = new Tree (shell, SWT.BORDER);
> GridData data = new GridData(SWT.LEFT, SWT.TOP, true, true);
> data.horizontalSpan = 1;
> tree.setLayoutData(data);
>
> for (int i=0; i<4; i++) {
> TreeItem iItem = new TreeItem (tree, 0);
> iItem.setText ("TreeItem (0) -" + i);
> for (int j=0; j<4; j++) {
> TreeItem jItem = new TreeItem (iItem, 0);
> jItem.setText ("TreeItem (1) -" + j);
> for (int k=0; k<4; k++) {
> TreeItem kItem = new TreeItem (jItem, 0);
> kItem.setText ("TreeItem (2) -" + k);
> for (int l=0; l<4; l++) {
> TreeItem lItem = new TreeItem (kItem, 0);
> lItem.setText ("TreeItem (3) -" + l);
> }
> }
> }
> }
> shell.open ();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
>
> Thanks!
>
> Bob
Re: Why doesn't grab grab? [message #452207 is a reply to message #452199] Tue, 15 March 2005 13:07 Go to previous messageGo to next message
Brad Reynolds is currently offline Brad ReynoldsFriend
Messages: 309
Registered: July 2009
Senior Member
My understanding is that grab just allocates the space. In order to
fill it you have to specify that you want the control to fill the space
as well. If you add another widget to the shell you'll see that it's
added at the bottom of the shell because the layout allocated all the
space it could to the tree, it just didn't fill the space. Grab is more
for allocation, fill actually takes care of consuming the allocated space.

public static void main(String[] args) {
Display display = new Display ();

Shell shell = new Shell (display);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
shell.setLayout(layout);
Tree tree = new Tree (shell, SWT.BORDER);
GridData data = new GridData(GridData.FILL_BOTH);
data.horizontalSpan = 1;
tree.setLayoutData(data);

for (int i=0; i<4; i++) {
TreeItem iItem = new TreeItem (tree, 0);
iItem.setText ("TreeItem (0) -" + i);
for (int j=0; j<4; j++) {
TreeItem jItem = new TreeItem (iItem, 0);
jItem.setText ("TreeItem (1) -" + j);
for (int k=0; k<4; k++) {
TreeItem kItem = new TreeItem (jItem, 0);
kItem.setText ("TreeItem (2) -" + k);
for (int l=0; l<4; l++) {
TreeItem lItem = new TreeItem (kItem, 0);
lItem.setText ("TreeItem (3) -" + l);
}
}
}
}

//Widget to show what grab does.
Text text = new Text(shell, SWT.BORDER);

shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}

Brad

Bob Foster wrote:
> Can somebody please explain to me why the tree in this slightly modified
> Snippet15 doesn't fill the entire shell?
>
> public class Snipped15Layout {
> public static void main(String[] args) {
> Display display = new Display ();
>
> Shell shell = new Shell (display);
> GridLayout layout = new GridLayout();
> layout.numColumns = 1;
> shell.setLayout(layout);
> Tree tree = new Tree (shell, SWT.BORDER);
> GridData data = new GridData(SWT.LEFT, SWT.TOP, true, true);
> data.horizontalSpan = 1;
> tree.setLayoutData(data);
>
> for (int i=0; i<4; i++) {
> TreeItem iItem = new TreeItem (tree, 0);
> iItem.setText ("TreeItem (0) -" + i);
> for (int j=0; j<4; j++) {
> TreeItem jItem = new TreeItem (iItem, 0);
> jItem.setText ("TreeItem (1) -" + j);
> for (int k=0; k<4; k++) {
> TreeItem kItem = new TreeItem (jItem, 0);
> kItem.setText ("TreeItem (2) -" + k);
> for (int l=0; l<4; l++) {
> TreeItem lItem = new TreeItem (kItem, 0);
> lItem.setText ("TreeItem (3) -" + l);
> }
> }
> }
> }
> shell.open ();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
>
> Thanks!
>
> Bob
Re: Why doesn't grab grab? [message #452254 is a reply to message #452205] Wed, 16 March 2005 01:48 Go to previous message
Eclipse UserFriend
Originally posted by: bob.objfac.com

Thanks!

Bob

Veronika Irvine wrote:
> It is grabbing, it is just not filling.
>
> You have:
>
> GridData data = new GridData(SWT.LEFT, SWT.TOP, true, true);
>
> which means the cell in the grid will grab any excess vertical or horizontal
> space, however, the widget will be aligned in the cell at its top left
> corner. If the cell is bigger than the preferred size of the widget, the
> widget will be smaller than the cell.
>
> If you change this to
>
> GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
>
> the cell will grab any excess vertical or horizontal space and the widget
> will be stretched (or shrunk as the case may be) to fill the cell
> horizontally and vertically.
>
> "Bob Foster" <bob@objfac.com> wrote in message
> news:d166go$607$1@www.eclipse.org...
>
>>Can somebody please explain to me why the tree in this slightly modified
>>Snippet15 doesn't fill the entire shell?
>>
>>public class Snipped15Layout {
>> public static void main(String[] args) {
>> Display display = new Display ();
>>
>> Shell shell = new Shell (display);
>> GridLayout layout = new GridLayout();
>> layout.numColumns = 1;
>> shell.setLayout(layout);
>> Tree tree = new Tree (shell, SWT.BORDER);
>> GridData data = new GridData(SWT.LEFT, SWT.TOP, true, true);
>> data.horizontalSpan = 1;
>> tree.setLayoutData(data);
>>
>> for (int i=0; i<4; i++) {
>> TreeItem iItem = new TreeItem (tree, 0);
>> iItem.setText ("TreeItem (0) -" + i);
>> for (int j=0; j<4; j++) {
>> TreeItem jItem = new TreeItem (iItem, 0);
>> jItem.setText ("TreeItem (1) -" + j);
>> for (int k=0; k<4; k++) {
>> TreeItem kItem = new TreeItem (jItem, 0);
>> kItem.setText ("TreeItem (2) -" + k);
>> for (int l=0; l<4; l++) {
>> TreeItem lItem = new TreeItem (kItem, 0);
>> lItem.setText ("TreeItem (3) -" + l);
>> }
>> }
>> }
>> }
>> shell.open ();
>> while (!shell.isDisposed()) {
>> if (!display.readAndDispatch ()) display.sleep ();
>> }
>> display.dispose ();
>> }
>>
>>Thanks!
>>
>>Bob
>
>
>
Previous Topic:Display timerexec delay limits
Next Topic:Debugging custom native SWT widget across JNI on Mac?
Goto Forum:
  


Current Time: Sun Nov 17 04:49:37 GMT 2019

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

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

Back to the top