Bug 92455 - [Forms] Form border on Text control is off by one
Summary: [Forms] Form border on Text control is off by one
Status: RESOLVED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.0.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Dejan Glozic CLA
QA Contact:
URL:
Whiteboard:
Keywords: polish
Depends on:
Blocks:
 
Reported: 2005-04-22 16:53 EDT by Claude Montpetit CLA
Modified: 2005-06-02 15:06 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Claude Montpetit CLA 2005-04-22 16:53:29 EDT
The horizontal border lines drawn around the Text control generated in a Form
context is off by one compared to the vertical lines.

When adding a Text Control to fit into a Composite using a GridLayout, you must
set margins in the GridLayout like this for the border to appear correctly:

    gridLayout.marginWidth = 1;
    gridLayout.marginHeight = 2;

It appears to me that the value shsould be the same for both margins values.

Here is sample code that reproduces this problem. The code uses "1" in both
margins. Change the height margin to 2 so see the borders correcly.


-----------------------------------------

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;

public class FormCompositeWithText extends Composite {

  private Text text;

  public FormCompositeWithText(Composite parent, int style) {
    super(parent, style);
    FormToolkit toolkit = new FormToolkit(parent.getDisplay());
    toolkit.adapt(this);
    toolkit.paintBordersFor(this);
    final GridLayout gridLayout = new GridLayout();
    gridLayout.horizontalSpacing = 0;
    gridLayout.verticalSpacing = 0;
    gridLayout.marginWidth = 1;
    gridLayout.marginHeight = 1;
    //gridLayout.marginHeight = 2; // Use this value for correctly drawn border
    setLayout(gridLayout);

    text = toolkit.createText(this, null, SWT.NONE);
    text.setLayoutData(new GridData(GridData.FILL_BOTH));
    text.setText("New Forms Text");
    //
  }

  public static void main(String[] args) {

    final Display display = new Display();
    final Shell shell = new Shell(display);

    shell.setSize(800, 600);

    Composite c = new FormCompositeWithText(shell, SWT.NONE);
    c.setBounds(10, 10, 150, 20);
    
    shell.open();
    while (!shell.isDisposed())
      if (!display.readAndDispatch())
        display.sleep();
    display.dispose();
  }  
}
Comment 1 Dejan Glozic CLA 2005-06-02 15:06:43 EDT
It works as designed (but perhaps it is not documented well). When borders are 
drawn for the Text control, padding is added vertically around the widget. 
Otherwise, the widget looks too short. If you check 'Text.computeTrim' method, 
you will notice that they do exactly the same thing if SWT.BORDER style is set.

Your solution is what we do everywhere in Eclipse - ensure that there are 2 
pixels vertical margin in a parent of the Text control when used in a form.