【发布时间】:2013-01-22 10:22:50
【问题描述】:
在调整外壳大小时,我在 RowLayout 中遇到了一些问题。我创建了复合并将布局设置为该复合的 RowLayout。在复合材料中添加了三个按钮。现在当我调整外壳大小时, 如果第三个按钮没有足够的空间,它应该下降。但它并没有下降。 谁能告诉代码中有什么问题?请在下面查看我的代码。
package com.rcp.mytraining.layout.composite;
import org.eclipse.swt.widgets.Composite;
public class ChatComposite extends Composite {
/**
* Create the composite.
*
* @param parent
* @param style
*/
public ChatComposite(Composite parent, int style) {
super(parent, style);
Composite comp = new Composite(parent, SWT.NONE);
// Color s = new Color(display, new RGB(30,30,30));
Color s = Display.getDefault().getSystemColor(1);
comp.setBackground(s);
RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
rowLayout.wrap = true;
rowLayout.pack = false;
comp.setLayout(rowLayout);
Button btnNewButton = new Button(comp, SWT.NONE);
btnNewButton.setText("New Button");
Button btnNewButton_1 = new Button(comp, SWT.NONE);
btnNewButton_1.setText("ss");
Button btnNewButton_2 = new Button(comp, SWT.NONE);
btnNewButton_2.setText("New Button");
comp.pack();
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
// shell.setSize(200, 200);
// shell.setLayout(new FillLayout());
ChatComposite chatComposite = new ChatComposite(shell, SWT.NONE);
shell.pack();
shell.open();
// chatComposite.pack();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
// display.dispose();
}
}
请看下面代码的不同之处。我想以同样的方式工作。上面的代码应该和下面的代码一样工作
package com.rcp.mytraining.layout.composite;
import org.eclipse.swt.widgets.Composite;
public class ChatComposite extends Composite {
/**
* Create the composite.
*
* @param parent
* @param style
*/
public ChatComposite(Composite parent, int style) {
super(parent, style);
/*
* RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
*
* // rowLayout.wrap = true; //rowLayout.pack = true;
* setLayout(rowLayout);
*
* Button btnNewButton = new Button(this, SWT.NONE);
* btnNewButton.setText("New Button");
*
* Button btnNewButton_1 = new Button(this, SWT.NONE);
* btnNewButton_1.setText("New Button");
*
* Button btnNewButton_2 = new Button(this, SWT.NONE);
* btnNewButton_2.setText("New Button");
*/
pack();
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
// shell.setSize(200, 200);
shell.setLayout(new FillLayout());
Composite comp = new Composite(shell, SWT.NONE);
// Color s = new Color(display, new RGB(30,30,30));
Color s = Display.getDefault().getSystemColor(1);
comp.setBackground(s);
RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
rowLayout.wrap = true;
// rowLayout.pack = true;
comp.setLayout(rowLayout);
Button btnNewButton = new Button(comp, SWT.NONE);
btnNewButton.setText("New Button");
Button btnNewButton_1 = new Button(comp, SWT.NONE);
btnNewButton_1.setText("ss");
Button btnNewButton_2 = new Button(comp, SWT.NONE);
btnNewButton_2.setText("New Button");
comp.pack();
// ChatComposite chatComposite = new ChatComposite(shell, SWT.NONE);
shell.pack();
shell.open();
// chatComposite.pack();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
// display.dispose();
}
}
【问题讨论】:
-
你说的“它不下来”是什么意思?可以发个截图吗?
-
我连续三个按钮。因此,当外壳调整大小时,它应该换行。这意味着当外壳调整到靠近第三个按钮的大小时,第三个按钮应该出现在第二行。清楚吗。