Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » GridLayout problem
GridLayout problem [message #466401] Tue, 10 January 2006 08:44 Go to next message
Koen is currently offline KoenFriend
Messages: 26
Registered: July 2009
Junior Member
Hello,

I want to create a form with labels on the left side and text boxes on the right side. I want the labels to be fully visible and leave the rest of the space for the text boxes. I am trying to do this using a grid layout, but I failed so far. Can anybode tell me what I am doing wrong in the following code snippet?

package test;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class GridLayoutTest {
private final static GridData labelData = new GridData(SWT.FILL, SWT.FILL,
false, false);

private final static GridData noSelectorEditData = new GridData(SWT.FILL,
SWT.FILL, true, false, 2, 1);

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
createContents(shell);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

private static void createContents(Shell shell) {
shell.setLayout(new FillLayout());
Composite composite = new Composite(shell, SWT.NONE);
GridLayout gl = new GridLayout(3, false);
composite.setLayout(gl);

addCombo(composite, "One Two Three");
addText(composite, "One");
addText(composite, "Two");
addText(composite, "Three");
}

private static void addText(Composite parent, String s) {
addLabel(parent, s);
final Text t = new Text(parent, SWT.SINGLE | SWT.BORDER);
t.setLayoutData(noSelectorEditData);
}

private static void addCombo(Composite parent, String s) {
addLabel(parent, s);
final Combo combo = new Combo(parent, SWT.BORDER);
combo.setLayoutData(noSelectorEditData);
combo.setVisibleItemCount(20);

combo.add("");
combo.add("value1");
combo.add("value2");
combo.add("value3");
}

private static void addLabel(Composite parent, String s) {
Label paramLabel = new Label(parent, SWT.NONE);
paramLabel.setLayoutData(labelData);
paramLabel.setText(s);
}
}

Thanks in advance,
Koen
Re: GridLayout problem [message #466403 is a reply to message #466401] Tue, 10 January 2006 09:00 Go to previous messageGo to next message
hortiz Mising name is currently offline hortiz Mising nameFriend
Messages: 96
Registered: July 2009
Member
Hi,

You can't reuse GridData objects !
See Javadoc for GridData :

"NOTE: Do not reuse GridData objects. Every control in a Composite that is
managed by a GridLayout must have a unique GridData object. If the layout
data for a control in a GridLayout is null at layout time, a unique
GridData object is created for it."
Re: GridLayout problem [message #466407 is a reply to message #466403] Tue, 10 January 2006 10:22 Go to previous message
Koen is currently offline KoenFriend
Messages: 26
Registered: July 2009
Junior Member
That solved it. Thanks!
Previous Topic:Regarding our new project!!!
Next Topic:How to change background color of 3 text widgets in same time?
Goto Forum:
  


Current Time: Thu Mar 28 12:23:02 GMT 2024

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

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

Back to the top