GridLayout problem [message #466401] |
Tue, 10 January 2006 08:44 |
Koen 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02900 seconds