java swt 实现界面的伸缩。 80
比如界面存在两个按钮,当我点击其中一个按钮,讲展开对应的内容,再次点击则收起内容。我写的代码如下(其中只有展开),当单机按钮1,未弹出其对应的内容,需要通过拖动窗口改变窗...
比如界面存在两个按钮,当我点击其中一个按钮,讲展开对应的内容,再次点击则收起内容。我写的代码如下(其中只有展开),当单机按钮1,未弹出其对应的内容,需要通过拖动窗口改变窗口大小才显示,请高手指明原因并修改正确。
public class a {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1,true));
final Composite c1 = new Composite(shell,SWT.NONE);
Composite c2 = new Composite(shell,SWT.NONE);
GridData gd = new GridData(SWT.FILL,SWT.CENTER,true,false);
c1.setLayoutData(gd);
c1.setLayout(new FillLayout(SWT.V_SCROLL));
gd = new GridData(SWT.FILL,SWT.CENTER,true,false);
c2.setLayoutData(gd);
c2.setLayout(new FillLayout());
Button b1 = new Button(c1,SWT.PUSH);
b1.setText("1");
b1.addSelectionListener(new SelectionAdapter(){
@Override
public void widgetSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
Button b3 = new Button(c1,SWT.CHECK);
b3.setText("123123");
shell.redraw();
shell.setVisible(false);
shell.setVisible(true);
}
});
Button b2 = new Button(c2,SWT.PUSH);
b2.setText("2");
shell.setSize(400,400);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
正确答案是shell.layout();或者shell.layout(true,true).试试即可 展开
public class a {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1,true));
final Composite c1 = new Composite(shell,SWT.NONE);
Composite c2 = new Composite(shell,SWT.NONE);
GridData gd = new GridData(SWT.FILL,SWT.CENTER,true,false);
c1.setLayoutData(gd);
c1.setLayout(new FillLayout(SWT.V_SCROLL));
gd = new GridData(SWT.FILL,SWT.CENTER,true,false);
c2.setLayoutData(gd);
c2.setLayout(new FillLayout());
Button b1 = new Button(c1,SWT.PUSH);
b1.setText("1");
b1.addSelectionListener(new SelectionAdapter(){
@Override
public void widgetSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
Button b3 = new Button(c1,SWT.CHECK);
b3.setText("123123");
shell.redraw();
shell.setVisible(false);
shell.setVisible(true);
}
});
Button b2 = new Button(c2,SWT.PUSH);
b2.setText("2");
shell.setSize(400,400);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
正确答案是shell.layout();或者shell.layout(true,true).试试即可 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询