Jface: custom FieldEditor bad layout

I'd like to create a custom FieldEditor for a preference page. the aim is to override ScaleFieldEditor to provide a Scale with two labels over it (one to display the min value, the other to display the max).

It made one. It is working but the layout is not good when I add a FileFieldeditor to preference page.

It's even worst if I add the FileFieldEditor immediately after the custom ScaleFieldEditor: http://imageshack.us/g/844/customscalelayoutok.png/ (Sorry, I cannot add images to this post).

I made a Composite which contains the 2 Labels and the Scale. I used a GridLayout:

public class ScaleWithLabelFieldEditor extends ScaleFieldEditor {

 * The maximum value label
private Label maxLabel;
 * The minimum value label
private Label minLabel;
 * A composite that contains the scale and the min & max values label
private Composite controls;

public ScaleWithLabelFieldEditor(String name, String labelText,
        Composite parent) {
    super(name, labelText, parent);

public ScaleWithLabelFieldEditor(String name, String labelText,
        Composite parent, int min, int max, int increment, int pageIncrement) {
    super(name, labelText, parent, min, max, increment, pageIncrement);

protected void doFillIntoGrid(Composite parent, int numColumns) {
    Control labelControl = getLabelControl(parent);
    GridData gd = new GridData();

    controls = getControls(parent, 2);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = numColumns -1;
    gd.grabExcessHorizontalSpace = true;

 * Initialize (if not done yet) the controls composite
 * @param parent
 *            the parent composite
 * @return the controls composite that contains the scaler and the min/max
 *         labels
protected Composite getControls(Composite parent, int numColumns) {
    if (controls == null) {
        controls = new Composite(parent, SWT.NONE);
        GridLayout layout = new GridLayout(numColumns, false);
        layout.numColumns = numColumns;

        // Initialize the min value label
        minLabel = getMinLabel(controls);
        minLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
        // Initialize the max value label
        maxLabel = getMaxLabel(controls);
        maxLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
        // Initialize the scale
        scale = getScale(controls);
        scale.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false, numColumns, 1));

    return controls;

 * Nothing to do, already handle with controls composite
protected void adjustForNumColumns(int numColumns) {
    // Nothing to do, already handle with controls composite

 * Update the scale and the labels above
protected void updateControls() {
    if (controls != null && !controls.isDisposed()) {
        // Update scale
        // Update labels

What I should do to make this field layout work? Did I miss something in GridLayout/GridData use?


The problem seems to be, that you did not implement the adjustForNumColumns(int numColumns) method. When you add the FileFieldEditor the number of columns changes from 2 to 3. And your field editor must adapt to that which it currently does not.

It seems like the horizontalSpan is not spanning until the end? So, may be you should try to remove -1 in gd.horizontalSpan = numColumns -1;

Need Your Help

Mercurial template: separator for tags and bookmarks

templates mercurial

Can I put space characters as separators only if I have any Tag or Bookmark?

Passing object/NSData between iOS devices

ios objective-c cocoa-touch nsdata game-center

I'm creating a game, turn based, and I was thinking of using Game Center to handle it, but the passed game-object is evidently max 64kb. Is there another way to pass objects between devices for thi...

How to avoid TopoJSON memory errors

javascript d3.js gis topojson

I'm attempting to create a TopoJSON file of school districts in the United States. I've laid out my workflow as follows:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.