SteWoo
SteWoo

Reputation: 468

What type of layout to use for RCP GUI

I'm creating my GUI for my RCP application using a GridLayout but I'm coming across problems because from what I understand a GridLayout adds elements in the order you create them/set their layout data? So, this doesn't offer a lot/any flexibility for moving elements around and adding new elements whilst keeping the same layout of previously placed elements.

Is there any other approach I should be using to make my GUI? I need it to be flexible and easy to specify the size and location of individual components rather than the component going in the next space.

At the momentGridLayout only allows me to specify the number of columns on the screen then specify the elements attributes (SWT.LEFT, SWT.CENTER) etc.

Here's my code to show what I mean:

import javax.annotation.PostConstruct;
import org.eclipse.swt.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;

public class CreateUI {

//Text area for the variables
Text variableArea;
Text methodArea;
Text otherArea;
Text fooArea;

@PostConstruct
//Annotation indicates the method is to be called after the class is constructed
public void createInterface(Composite parent){

    int columns =4;

    //Set the layout of the parent (the Part) to a grid layout
    parent.setLayout(new GridLayout(columns, true));

    variableArea = new Text(parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    variableArea.setText("Hello");
    variableArea.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));

    methodArea = new Text(parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    methodArea.setText("Hello2");
    methodArea.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));

    otherArea = new Text(parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    otherArea.setText("Hello3");
    otherArea.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));

    fooArea = new Text(parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    fooArea.setText("Hello4");
    fooArea.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));


  }
}

This produces this:

At the moment there's only those 4 Text areas there as an example but I'm going to have multiple Text areas, Buttons, Drop Down Menu's etc later on and I want to be able to format them easier and position them freely.

In relation to the above example I want to be able to position those 4 Text areas on top of one another in a column to display information and have other elements positioned freely in the remaining space.

Any pointers would be great for what I should be using.

Upvotes: 0

Views: 306

Answers (1)

Alexey Romanov
Alexey Romanov

Reputation: 170919

MigLayout is quite flexible. From built-in layouts, FormLayout is also a decent choice, but it's quite a bit harder to get right than GridLayout, so I'd only recommend using it if you find GridLayout really unsuitable.

Upvotes: 1

Related Questions