Skip to main content


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 07:47 Go to next message
Philipp M. Fischer is currently offline Philipp M. FischerFriend
Messages: 67
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 08:05]

Report message to a moderator

Re: GridLayout Problems in Forms [message #722150 is a reply to message #719144] Sun, 04 September 2011 18:30 Go to previous message
Philipp M. Fischer is currently offline Philipp M. FischerFriend
Messages: 67
Registered: November 2010
Location: Germany
Member
Reported as Bug 356596
Previous Topic:Dialog missing title image
Next Topic:filtering comboviewer on linux and mac
Goto Forum:
  


Current Time: Thu Apr 25 09:57:34 GMT 2024

Powered by FUDForum. Page generated in 0.03119 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top