Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set rows and columns of a widget in grid layout?
    text
    copied! <p>I am using grid layout in a shell. I want to control the location of widgets. As you can see the bottom buttons have to be on row 4. I am using windowbuilder plugin and it can place them in desired places.</p> <p><img src="https://i.stack.imgur.com/hdGhg.png" alt="my shell using windowbuilder"></p> <p>The problem is I can't see the placement instruction in source code. How can I place them the programmatic way. Here is the source code window builder generates.</p> <pre class="lang-java prettyprint-override"><code>package dgsj.Chapter04.examples.ch4; import org.eclipse.swt.widgets.*; public class GridLayout2x2 { private static GridData data_1; private static GridData data_2; public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setMinimumSize(new Point(123, 30)); shell.setSize(126, 123); GridLayout layout = new GridLayout(); layout.numColumns = 3; shell.setLayout(layout); GridData data = new GridData(GridData.FILL_BOTH); data.grabExcessHorizontalSpace = false; data.widthHint = 200; data.grabExcessVerticalSpace = false; Button one = new Button(shell, SWT.PUSH); one.setText("one"); one.setLayoutData(data); data = new GridData(GridData.FILL_BOTH); Button two = new Button(shell, SWT.PUSH); two.setText("two"); two.setLayoutData(data); new Label(shell, SWT.NONE); new Label(shell, SWT.NONE); data_2 = new GridData(GridData.FILL_BOTH); Button four = new Button(shell, SWT.PUSH); four.setText("four"); four.setLayoutData(data_2); new Label(shell, SWT.NONE); new Label(shell, SWT.NONE); new Label(shell, SWT.NONE); new Label(shell, SWT.NONE); new Label(shell, SWT.NONE); Button btnNewButton = new Button(shell, SWT.NONE); btnNewButton.setText("New Button"); data_1 = new GridData(GridData.FILL_BOTH); data_1.grabExcessVerticalSpace = false; data_1.grabExcessHorizontalSpace = false; Button three = new Button(shell, SWT.PUSH); three.setText("three"); three.setLayoutData(data_1); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload