刚学习使用SWT做界面,当鼠标拖动窗改变窗口的大小或者窗口最大化时,里面的组件却没有随着窗口变化,请问如何使组件随着窗口变化?附一个简单的例子import org.eclipse.swt.*;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;public class GroupTest {
public static void main(String args[])
{
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setSize(240, 300);
shell.setText("分组框");
shell.setToolTipText("Shell容器");
final Group group1 = new Group(shell,SWT.NONE);
group1.setBounds(40,25, 160,60);
group1.setText("请选择");
Button bt1 = new Button(group1,SWT.RADIO);
bt1.setBounds(20, 10, 100, 25);
bt1.setText("Group实例");
Button bt2 = new Button(group1,SWT.RADIO);
bt2.setBounds(20, 35, 100, 25);
bt2.setText("Button实例");
final Group group2 = new Group(shell,SWT.NONE);
group2.setBounds(40,110, 160,90);
group2.setText("Group2");
Button bt3 = new Button(group2,SWT.NORMAL);
bt3.setBounds(20, 10, 50, 25);
bt3.setText("Normal");
Button bt4 = new Button(group2,SWT.CHECK);
bt4.setBounds(20, 35, 100, 25);
bt4.setText("Check");
Button bt5 = new Button(group2,SWT.TOGGLE);
bt5.setBounds(20, 60, 50, 25);
bt5.setText("TOGGLE");
shell.open();
while(!shell.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}}
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;public class GroupTest {
public static void main(String args[])
{
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setSize(240, 300);
shell.setText("分组框");
shell.setToolTipText("Shell容器");
final Group group1 = new Group(shell,SWT.NONE);
group1.setBounds(40,25, 160,60);
group1.setText("请选择");
Button bt1 = new Button(group1,SWT.RADIO);
bt1.setBounds(20, 10, 100, 25);
bt1.setText("Group实例");
Button bt2 = new Button(group1,SWT.RADIO);
bt2.setBounds(20, 35, 100, 25);
bt2.setText("Button实例");
final Group group2 = new Group(shell,SWT.NONE);
group2.setBounds(40,110, 160,90);
group2.setText("Group2");
Button bt3 = new Button(group2,SWT.NORMAL);
bt3.setBounds(20, 10, 50, 25);
bt3.setText("Normal");
Button bt4 = new Button(group2,SWT.CHECK);
bt4.setBounds(20, 35, 100, 25);
bt4.setText("Check");
Button bt5 = new Button(group2,SWT.TOGGLE);
bt5.setBounds(20, 60, 50, 25);
bt5.setText("TOGGLE");
shell.open();
while(!shell.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}}
public class GroupTest {
public static void main(String args[])
{
final Display display = new Display();
final Shell shell = new Shell(display, SWT.CLOSE | SWT.MAX | SWT.TITLE | SWT.BORDER);
shell.setSize(240, 300);
shell.setText("分组框");
shell.setToolTipText("Shell容器");
GridLayout shellLayout = new GridLayout(1,false);
shellLayout.marginHeight = 15;
shellLayout.marginWidth = 15;
shell.setLayout(shellLayout);
final Group group1 = new Group(shell,SWT.NONE);
GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(group1);
GridLayout group1Layout = new GridLayout(1,false);
group1Layout.marginHeight = 15;
group1Layout.marginWidth = 15;
group1.setLayout(group1Layout);
group1.setText("请选择");
Button bt1 = new Button(group1,SWT.RADIO);
bt1.setText("Group实例");
GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(bt1);
Button bt2 = new Button(group1,SWT.RADIO);
GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(bt2);
bt2.setText("Button实例");
final Group group2 = new Group(shell,SWT.NONE);
GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(group2);
GridLayout group2Layout = new GridLayout(1,false);
group2Layout.marginHeight = 15;
group2Layout.marginWidth = 15;
group2.setLayout(group2Layout);
group2.setText("Group2");
Button bt3 = new Button(group2,SWT.NORMAL);
GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(bt3);
bt3.setText("Normal");
Button bt4 = new Button(group2,SWT.CHECK);
GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(bt4);
bt4.setText("Check");
Button bt5 = new Button(group2,SWT.TOGGLE);
GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(bt5);
bt5.setText("TOGGLE");
shell.open();
while(!shell.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}