Font font = parent.getFont();\n setLayout(new FillLayout());\n\n SashForm sashForm = new SashForm(this, SWT.VERTICAL);\n\n FormToolkit toolkit = new FormToolkit(getParent().getDisplay());\n Section section = toolkit.createSection(sashForm,\n Section.DESCRIPTION | ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED);\n section.setLayoutData(new GridData(GridData.FILL_BOTH));\n section.setLayout(new GridLayout());\n section.setText(\"Section Title\");\n Composite controlComposite = toolkit.createComposite(section);\n GridLayout controlLayout = new GridLayout();\n controlLayout.numColumns = 2;\n controlLayout.verticalSpacing = 20;\n controlComposite.setLayout(controlLayout);\n section.setClient(controlComposite);\n\n Font bold = ResourceManager.getBoldFont(font);\n\n Label textLabel = toolkit.createLabel(controlComposite, \"Title:\", SWT.BOLD);\n GridData gd = new GridData();\n gd.horizontalSpan = 1;\n textLabel.setLayoutData(gd);\n textLabel.setFont(bold);\n\n textBox = new ExtendedText(controlComposite, SWT.BORDER | SWT.SINGLE, false);\n gd = new GridData(GridData.FILL_HORIZONTAL);\n gd.horizontalSpan = 1;\n gd.verticalSpan = 2;\n textBox.setLayoutData(gd);\n
\n\nThe ExtendedText class is an extension of StyledText. The important bits of it are this:
\n\n GridData gd_bg = new GridData(GridData.FILL_BOTH);\n setLayoutData(gd_bg);\n\n final GridLayout gridLayout = new GridLayout();\n gridLayout.verticalSpacing = 0;\n gridLayout.marginWidth = 0;\n gridLayout.marginHeight = 0;\n gridLayout.horizontalSpacing = 0;\n gridLayout.numColumns = 1;\n gridLayout.makeColumnsEqualWidth = true;\n\n sashForm.setWeights(new int[] { 1, 1 });\n
\n","author":{"@type":"Person","name":"Chris Clark"},"upvoteCount":0,"answerCount":1,"acceptedAnswer":null}}Reputation: 340
I had an Eclipse plug-in app (ten-year-old code, no documentation, etc.) dropped in my lap and while adding new features to it, I noticed that when a panel is resized, the text boxes change size continuously while the separator is being dragged.
As you can see in the second picture, the text boxes are kind of randomly sized. Is there a setting in SWT that will prevent this from happening?
Here's how I'm creating one of the text boxes. The others are basically clones of this:
Font font = parent.getFont();
setLayout(new FillLayout());
SashForm sashForm = new SashForm(this, SWT.VERTICAL);
FormToolkit toolkit = new FormToolkit(getParent().getDisplay());
Section section = toolkit.createSection(sashForm,
Section.DESCRIPTION | ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED);
section.setLayoutData(new GridData(GridData.FILL_BOTH));
section.setLayout(new GridLayout());
section.setText("Section Title");
Composite controlComposite = toolkit.createComposite(section);
GridLayout controlLayout = new GridLayout();
controlLayout.numColumns = 2;
controlLayout.verticalSpacing = 20;
controlComposite.setLayout(controlLayout);
section.setClient(controlComposite);
Font bold = ResourceManager.getBoldFont(font);
Label textLabel = toolkit.createLabel(controlComposite, "Title:", SWT.BOLD);
GridData gd = new GridData();
gd.horizontalSpan = 1;
textLabel.setLayoutData(gd);
textLabel.setFont(bold);
textBox = new ExtendedText(controlComposite, SWT.BORDER | SWT.SINGLE, false);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 1;
gd.verticalSpan = 2;
textBox.setLayoutData(gd);
The ExtendedText class is an extension of StyledText. The important bits of it are this:
GridData gd_bg = new GridData(GridData.FILL_BOTH);
setLayoutData(gd_bg);
final GridLayout gridLayout = new GridLayout();
gridLayout.verticalSpacing = 0;
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
gridLayout.horizontalSpacing = 0;
gridLayout.numColumns = 1;
gridLayout.makeColumnsEqualWidth = true;
sashForm.setWeights(new int[] { 1, 1 });
Upvotes: 0
Views: 976
Reputation: 340
Okay, after digging in a little deeper, I got it working as expected.
First, the controlComposite and controlLayout objects are now created using
Composite controlComposite = new Composite(section, SWT.NONE)
controlComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
controlComposite.setBackground(section.getBackground());
GridLayout controlLayout = new GridLayout(2, true);
controlLayout.marginHeight = 20;
controlLayout.marginWidth = 0;
controlLayout.verticalSpacing = 10;
controlLayout.horizontalSpacing = 0;
controlComposite.setLayout(controlLayout);
section.setClient(controlComposite);
Once I did that, things started to stabilize. I also ended up tweaking the weights to this:
sashForm.setWeights(new int[] { 2, 3 });
It's not perfect, but it'll do for now.
Thanks to @greg-449 and @Baz for taking a look
Upvotes: 1