Another GridData problem... [message #457648] |
Thu, 30 June 2005 12:07 |
hortiz Mising name Messages: 96 Registered: July 2009 |
Member |
|
|
Hi,
I have a problem using GridData objects.
The code below shows the problem: I would like that the size of the two
GridData instances containing the leftCanvas and rightCanvas be 10 px
(width) * 50 px (height).
However, we could see that the left Canvas (the red one) is wider : there
is still a green area on the left of it ; and the right Canvas (the yellow
one) is wider two : there is still a green area on the right of it.
thanks for your help,
Helene
package test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class SelectionToolBar {
private Composite selectionToolBarComposite;
public SelectionToolBar(Composite parent) {
selectionToolBarComposite = new Composite(parent, SWT.BORDER);
selectionToolBarComposite.setBackground(parent.getDisplay(). getSystemColor(SWT.COLOR_GREEN));
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
gridLayout.marginBottom = 0;
gridLayout.marginHeight = 0;
gridLayout.marginLeft = 0;
gridLayout.marginTop = 0;
gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 0;
selectionToolBarComposite.setLayout(gridLayout);
GridData gridData = new GridData();
// gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
selectionToolBarComposite.setLayoutData(gridData);
// left corner
Canvas leftCanvas = new Canvas(selectionToolBarComposite,
SWT.NONE);
gridData = new GridData();
gridData.widthHint = 10;
gridData.heightHint = 50;
leftCanvas.setLayoutData(gridData);
leftCanvas.setBackground(selectionToolBarComposite.getDispla y().getSystemColor(SWT.COLOR_RED));
Composite buttonsComposite = new
Composite(selectionToolBarComposite, SWT.NONE);
gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
buttonsComposite.setLayoutData(gridData);
gridLayout = new GridLayout();
gridLayout.numColumns = 3;
gridLayout.makeColumnsEqualWidth = true;
buttonsComposite.setLayout(gridLayout);
// Hardware
Button hardwareButton = new Button(buttonsComposite, SWT.PUSH);
hardwareButton.setText("Hardware");
gridData = new GridData();
hardwareButton.setLayoutData(gridData);
// Settings
Button settingsButton = new Button(buttonsComposite, SWT.PUSH);
settingsButton.setText("Settings");
gridData = new GridData();
settingsButton.setLayoutData(gridData);
// Command
Button commandButton = new Button(buttonsComposite, SWT.PUSH);
commandButton.setText("Command");
gridData = new GridData();
commandButton.setLayoutData(gridData);
// right corner
Canvas rightCanvas = new Canvas(selectionToolBarComposite,
SWT.NONE);
gridData = new GridData();
gridData.widthHint = 10;
gridData.heightHint = 50;
rightCanvas.setLayoutData(gridData);
rightCanvas.setBackground(selectionToolBarComposite.getDispl ay().getSystemColor(SWT.COLOR_YELLOW));
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
shell.setSize(800, 600);
SelectionToolBar stb = new SelectionToolBar(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.02713 seconds