1
我有一個5列網格佈局的組合,它包含 一些按鈕。現在是否可以添加任何其他控件到 GridLayout的特定位置?例如,我想在第三列的第一行添加一個TextField,即代替Button3 ,並且按鈕3應該下到最後一行,即按鈕7之後。 GridLayout中可以使用任何類型的動態定位?動態組件網格佈局定位
package zrcp;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class LayoutExample {
protected Shell shell;
/**
* Launch the application.
*
* @param args
*/
public static void main(String[] args) {
try {
LayoutExample window = new LayoutExample();
window.open();
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
shell.setLayout(new GridLayout(5, false));
Button btnNewButton = new Button(shell, SWT.NONE);
btnNewButton.setText("Button1");
Button btnNewButton_1 = new Button(shell, SWT.NONE);
btnNewButton_1.setText("Button2");
Button btnNewButton_2 = new Button(shell, SWT.NONE);
btnNewButton_2.setText("Button3");
Button btnNewButton_3 = new Button(shell, SWT.NONE);
btnNewButton_3.setText("Button4");
Button btnNewButton_4 = new Button(shell, SWT.NONE);
btnNewButton_4.setText("Button5");
Button btnNewButton_5 = new Button(shell, SWT.NONE);
btnNewButton_5.setText("Button6");
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
Button btnNewButton_6 = new Button(shell, SWT.NONE);
btnNewButton_6.setText("Button7");
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
}
}