How to make window to be able to be thin in SWT?
java, swt
Solution
The reason for this is that Windows requires a minimal window width to be able to add the min/max/close buttons and the window title.
The default style of the `Shell` is
SWT.SHELL_TRIM = SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE
Unfortunately, you can't even get around this by forcing the `Shell` to just show the close button:
Shell shell = new Shell(display, SWT.CLOSE | SWT.RESIZE);
Windows will still enforce the minimal width.
Concluding, I'm afraid there is nothing you can do about it if you still require the window controls. If you don't need the window controls, then you can use
Shell shell = new Shell(display, SWT.RESIZE);
Here is example code:
public static void main(String[] args)
{
RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
rowLayout.wrap = true;
Display display = new Display();
Shell shell = new Shell(display, SWT.RESIZE);
shell.setLayout(new FillLayout());
shell.setMinimumSize(1, 1);
// shell.setLayout(rowLayout);
Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(rowLayout);
Label label;
for (int i = 0; i < 100; ++i)
{
// label = new Label(shell, SWT.NONE);
label = new Label(composite, SWT.NONE);
label.setText("A");
}
shell.pack();
shell.open();
shell.setSize(50, 200);
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
}
And this is what it looks like:
Problem
Why doesn't the following application allow me to make window very thin? The minimal width allows to layout 3 columns of images while I wish to make one-column-wide possible. How to allow narrowing more? ``` package tests; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; public class TryRowLayout { public static void main(String[] args) { RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL); rowLayout.wrap = true; Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setMinimumSize(1, 1); //shell.setLayout(rowLayout); Composite composite = new Composite(shell, SWT.NONE); composite.setLayout(rowLayout); Image image = new Image(display, "images/alt_window_32.gif"); Label label; for(int i=0; i<100; ++i) { //label = new Label(shell, SWT.NONE); label = new Label(composite, SWT.NONE); label.setImage(image); } shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } } ```