[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [platform-swt-dev] SWT program
|
public static void main (String [] args) {
Display display = new Display();
Shell shell = new Shell(display);
// Create the layout.
GridLayout layout = new GridLayout();
// Optionally set layout fields.
// Set the layout into the composite.
shell.setLayout(layout);
// Create the children of the composite.
Button button1 = new Button(shell, SWT.PUSH);
GridData oGD = new GridData();
oGD.grabExcessHorizontalSpace = false;
oGD.grabExcessVerticalSpace = false;
oGD.widthHint = 30;
oGD.heightHint = 10;
button1.setLayoutData(oGD);
button1.setText("Button1");
// button1.setSize(30,10);
shell.pack();
shell.open();
System.out.println(button1.getSize());
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
}
}
If you use Layout, you must use layout data to fix the size of controls
Olivier
lvyb wrote:
空白
Hi,can someone tell me why my code marked red below doesn't work?
public class LayoutDataTest {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
// Create the layout.
GridLayout layout = new GridLayout();
// Optionally set layout fields.
// Set the layout into the composite.
shell.setLayout(layout);
// Create the children of the composite.
Button button1 = new Button(shell, SWT.PUSH);
button1.setText("Button1");
button1.setSize(30,10);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
}
}
Thanks,
kian