Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » GridLayout Problems in Forms(Layout changes unexpectedly with changing order of columns)
GridLayout Problems in Forms [message #719144] Fri, 26 August 2011 03:47 Go to next message
Phil M. Fischer is currently offline Phil M. Fischer
Messages: 60
Registered: November 2010
Location: Germany
Member
Hi All,

I am currently facing a layout problem with the GridLayout in Forms. It looks like a bug to me, but I am not a 100% sure. Maybe someone discovered this issue as well and knows a way around.

The following code shows a little example, that works as expected. It creates a View containing a Form with some Widgets:

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.Section;

public class SampleView extends ViewPart {

	private FormToolkit toolkit;
	
	@Override
	public void createPartControl(Composite parent) {
		// Get the toolkit
		Display display = parent.getDisplay();
		toolkit = new FormToolkit(display);
		
		// Add the Form as container for all other widgets
		Form form = toolkit.createForm(parent);
		
		// Set a GridLayout with just one Column to the Form
		GridLayout layout = new GridLayout(1, true);
		layout.horizontalSpacing = 2;
		layout.verticalSpacing = 2;
		form.getBody().setLayout(layout);
		
		// Add the sections to the form
		createImageGeneral(form.getBody());
	}
	
	/**
	 * Creates the images's general-information Section
	 * @param parent The parent Composite to which to attach the section
	 */
	private void createImageGeneral(Composite parent) {
		// Create the Section and attach the LayoutData so that the form can
		// place it correctly. The Section is supposed to take all vertical space
		Section section = toolkit.createSection(parent, Section.TITLE_BAR);
		section.setText("Image General IInformations");
		Composite composite = toolkit.createComposite(section);
		section.setClient(composite);
		section.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
	
		// The client Composite of the section will get a three Column Grid Layout
		final int THREE_COLUMNS = 3;
		composite.setLayout(new GridLayout(THREE_COLUMNS, false));

		// Place the widgets
		Label labelColor = toolkit.createLabel(composite, "Select Color:");
		Text  textColor = toolkit.createText(composite, "OxFFFFFF", SWT.READ_ONLY);
		Button buttonColor = toolkit.createButton(composite, "...", SWT.NONE);

		Label labelReset = toolkit.createLabel(composite, "Reset Data:");
		Button buttonReset = toolkit.createButton(composite, "Reset", SWT.NONE);

		Label labelTrans = toolkit.createLabel(composite, "Color Gradient Order:");
		Text comboTrans = toolkit.createText(composite, "Test");
	
		// Do the Layout
		GridData gridDataBeg = new GridData(GridData.BEGINNING, GridData.CENTER, false, false);
		GridData gridDataEnd = new GridData(GridData.END, GridData.CENTER, false, false);
		GridData gridDataMid = new GridData(GridData.FILL, GridData.CENTER, true, false);
		GridData gridDataSpan2 = new GridData(GridData.FILL, GridData.CENTER, false, false);
		gridDataSpan2.horizontalSpan = 2;
	
		labelTrans.setLayoutData(gridDataBeg);
		comboTrans.setLayoutData(gridDataSpan2);
		
		labelColor.setLayoutData(gridDataBeg);
		textColor.setLayoutData(gridDataMid);
		buttonColor.setLayoutData(gridDataEnd);
		
		labelReset.setLayoutData(gridDataBeg);
		buttonReset.setLayoutData(gridDataSpan2);
	}

	@Override
	public void setFocus() {
	}
}


The code creates the following View, with the correct layout:

index.php/fa/3768/0/

Changing the following lines of code, the layout changes as well:

		Label labelTrans = toolkit.createLabel(composite, "Color Gradient Order:");
		Text comboTrans = toolkit.createText(composite, "Test");

		Label labelReset = toolkit.createLabel(composite, "Reset Data:");
		Button buttonReset = toolkit.createButton(composite, "Reset", SWT.NONE);


As expected the order of the columns changes but the layout as well. The column containing the Labels is now adjusted to the width of the last Label. As a consequence the other Labels are not displayed correctly and become unreadable:

index.php/fa/3769/0/

For me this looks wrong, but maybe i have not understood the GridLayout in full depth, yet.

Cheers

Phil

[Updated on: Fri, 26 August 2011 04:05]

Report message to a moderator

Re: GridLayout Problems in Forms [message #722150 is a reply to message #719144] Sun, 04 September 2011 14:30 Go to previous message
Phil M. Fischer is currently offline Phil M. Fischer
Messages: 60
Registered: November 2010
Location: Germany
Member
Reported as Bug 356596
Previous Topic:[Forms] Header layout problem caused by message icons
Next Topic:Set handler to parameterized comman
Goto Forum:
  


Current Time: Sat Aug 23 07:32:36 EDT 2014

Powered by FUDForum. Page generated in 0.01586 seconds