java - How to put all the button in the same row? -


I have created several link buttons.

I want all the buttons to be in the same line

Every time I put a new button, it moves it to the next line.

  Control of Public Zero (Composite Parent) {myComposite = new composite (parent, SWT.NONE); Grid layout descriptionsidegrid layout = new grid layout (); DetailsSideGridLayout.numColumns = 1; MyComposite.setLayout (detailsSideGridLayout); GridDataGridataData = new grid data (); MyGridData.horizontalAlignment = SWT.FILL; MyGridData.grabExcessHorizontalSpace = True; MyGridData.verticalAlignment = SWT.FILL; MyGridData.grabExcessVerticalSpace = True; MyComposite.setLayoutData (myGridData); DeComposite = new composite (myComposite, SWT.NONE); Rowlate DGgrid Layout = New Rowout (SWT.HORIZONTAL); DeComposite.setLayout (deGridLayout); Gridata deGridData = New GridData (); DeGridData.horizontalAlignment = SWT.FILL; DeGridData.grabExcessHorizontalSpace = True; Create LinkLabelBeget Rating = (Decomposite); CreateDetailsde.setLayoutData (deGridData); // Create another button LinkBack (CreateDefender) myComposite.layout (); Private linksLabel createDetailsde (Composite DetailsComposuit) {// TODO Resource Manager Implementation LinkLabel LinkLabel = New LinkLabel (DetailsComposit, SWT.NONE); LinkLabel.setText ("test"); // $ Non-NLS-1 $ return linkLabel; } Make Private LinkLabelLinkleLabel (Composite DetailsComposuit) {LinkLabel LinkLabel = New LinkLabel (DetailsCompany, SWT.NONE); LinkLabel.setText ("test2"); // $ Non-NLS-1 $ return linkLabel; }  

I get the error message error is org.eclipse.swt.layout.GridData can not be placed on org.eclipse.swt.layout.RowData

Grid layout You only have one column ( deGridLayout.numColumns = 1; ). There are two things that you can do:

  1. The number of columns you have to set up GridLayout , the button s
  2. instead of rollout instead of SWT.HORIZONTAL (you do not have to define the number of items here)

Here is some example code:

  public static zero main (string [] args) {display display = new display (); Last Shell Shell = New Shell (Display); Shell.setText ("StackOverflow"); Shell.setLayout (new grid layout (1, wrong)); Group first = new group (shell, SWT.NONE); First.setText ("RowLayout"); First.withoutout (new roleout (SWT.HORIZONTAL)); Group second = new group (shell, SWT.NONE); Second.setText ("GridLayout"); Second.setLayout (new grid layout (5, wrong)); (Int i = 1; i <5; i ++) {new button (first, SWT.PUSH) .set text ("button" + i); New button (second, SWT.PUSH) .set text ("button" + i); } Shell.pack (); Shell.open (); While (! Shell.isDisposed ()) {if (! Display.readAndDispatch ()) display.sleep (); } Display.dispose (); }  

This is what looks like this:

Comments