Reputation: 1787
I am working on the SWT,with the following code I got the UI as shown in figure(1).In My application information bar appears only certain situations and I am trying to make all three buttons to be aligned always right-side.
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new GridLayout(3, false));
comp.setLayoutData(gridData);
infoArea = new InformationArea(comp, "Example 5");
infoArea.create();
infoArea.setRowLimit(2);
infoArea.setVisible(false);
buttonComposite = new Composite(comp, SWT.NONE);
buttonComposite.setLayout(new GridLayout(3, false));
gridData = new GridData(SWT.END, SWT.BOTTOM, true, false);
gridData.horizontalSpan = 1;
buttonComposite.setLayoutData(gridData);
if (isAddingNewNode() && stepNode.getParent() == null) {
addButton = new Button(buttonComposite, SWT.PUSH);
addButton.setText("Add"));
gridData = new GridData(SWT.END, SWT.BOTTOM, false, false);
gridData.widthHint = 80;
addButton.setLayoutData(gridData);
addButton.setEnabled(false);
}
okButton = new Button(buttonComposite, SWT.PUSH);
okButton .setText("Ok"));
gridData = new GridData(SWT.RIGHT, SWT.BOTTOM, false, false);
gridData.widthHint = 80;
okButton.setLayoutData(gridData);
okButton.setEnabled(false);
okButtonPressed = false;
cancelButton = new Button(buttonComposite, SWT.PUSH);
cancelButton.setText("Cancel")
gridData = new GridData();
gridData.widthHint = 80;
cancelButton.setLayoutData(gridData);
cancelButton.setEnabled(true);
cancelButtonPressed = false;
I tried with modifying grabAccessHorizonalSpace in line(gridData = new GridData(SWT.END, SWT.BOTTOM, false, false);)( 3rd Parameter) to false like below but got the result as in figure (2) and figure (3)
buttonComposite.setLayout(new GridLayout(3, false));
gridData = new GridData(SWT.END, SWT.BOTTOM, false, false);
gridData.horizontalSpan = 1;
I am trying to build the UI shown in Figure(4)
Upvotes: 0
Views: 957
Reputation: 36904
This should give you an idea how to achieve what you want:
public static void main(String[] args)
{
Display display = new Display();
Shell shell = new Shell();
shell.setText("StackOverflow");
shell.setLayout(new GridLayout(4, false));
final Label information = new Label(shell, SWT.CENTER);
information.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
information.setText("Some information text");
information.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
String[] buttons = {"Add", "OK", "Cancel"};
for(String text : buttons)
{
Button button = new Button(shell, SWT.PUSH);
button.setText(text);
button.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
}
Button hide = new Button(shell, SWT.PUSH);
hide.setText("Hide/Show");
hide.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 4, 1));
hide.addListener(SWT.Selection, new Listener()
{
@Override
public void handleEvent(Event arg0)
{
information.setVisible(!information.getVisible());
}
});
shell.pack();
shell.setSize(500, shell.getSize().y);
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}
Looks liks this:
Upvotes: 1