I am facing some problem in RowLayout while resizing the shell. I created the composite and set the layout as RowLayout for that composite. Added three Buttons inside the composite. Now when I resize the shell, if there is not enough space for the third button, it should come down. But it is not coming down. Could anyone tell whats wrong in the code? Please see my code below.
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();
}
}
Please see the difference in the below code. I wanted to work in the same way. The above code should work in the sameway as the below code works
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();
}
}