Note that there are some explanatory texts on larger screens.

plurals
  1. POJface: custom FieldEditor bad layout
    text
    copied!<p>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).</p> <p>It made one. It is working but the layout is not good when I add a FileFieldeditor to preference page.</p> <p>It's even worst if I add the FileFieldEditor immediately after the custom ScaleFieldEditor: <a href="http://imageshack.us/g/844/customscalelayoutok.png/" rel="nofollow">http://imageshack.us/g/844/customscalelayoutok.png/</a> (Sorry, I cannot add images to this post).</p> <p>I made a Composite which contains the 2 Labels and the Scale. I used a GridLayout:</p> <pre><code>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 &amp; 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); } @Override protected void doFillIntoGrid(Composite parent, int numColumns) { Control labelControl = getLabelControl(parent); GridData gd = new GridData(); labelControl.setLayoutData(gd); controls = getControls(parent, 2); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = numColumns -1; gd.grabExcessHorizontalSpace = true; controls.setLayoutData(gd); updateControls(); parent.layout(); } /** * 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; controls.setLayout(layout); // 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 */ @Override 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 &amp;&amp; !controls.isDisposed()) { // Update scale scale.setMinimum(getMinimum()); scale.setMaximum(getMaximum()); scale.setIncrement(getIncrement()); scale.setPageIncrement(getPageIncrement()); // Update labels maxLabel.setText(Integer.toString(getMaximum())); minLabel.setText(Integer.toString(getMinimum())); } } </code></pre> <p>What I should do to make this field layout work? Did I miss something in GridLayout/GridData use?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload