'How to set a composite to the right side of the screen

I have created 2 labels and I wish to move these labels to the right most side of the screen. I have created a new composite for the 2 labels and set the labels with the label composite. But now the label is somewhere towards the center. I have 7 other widgets already in the screen.

Following is the code I used:

Composite blockControls = this.formToolkit.createComposite(this.mainComposite, SWT.NONE);
blockControls.setLayout(GridLayoutFactory.fillDefaults().numColumns(8).create());
blockControls.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));


Composite labelComposite = new Composite(blockControls, SWT.NONE);
GridLayout layout = new GridLayout();
labelComposite.setLayout(layout);
GridData layoutData = new GridData(SWT.END, SWT.END, true, true);
labelComposite.setLayoutData(layoutData);
labelComposite.setBackground(GUIHelper.COLOR_WHITE);

Label mappedEleLabel = new Label(labelComposite, SWT.LEAD);
mappedEleLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
mappedEleLabel.setText("hello");
mappedEleLabel.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_YELLOW));
mappedEleLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));

Label unmappedEleLabel = new Label(labelComposite, SWT.LEAD);
unmappedEleLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
unmappedEleLabel.setText("world");
unmappedEleLabel.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GREEN));
unmappedEleLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));


Solution 1:[1]

You can use FormData but there are many ways. FormData objects specify how each widget in a FormLayout will be laid out.

But the solution depends on the arrangement of the other 7 widgets.

I recommend this article: Layouts in SWT

Though the article may seem deprecated , Layouts in SWT haven't changed.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daniel Scerpa