Tuesday, 20 August 2013

SashForm children default sizes

SashForm children default sizes

I have a SashForm, and the objective is simply to make a form with 2
children: a table and a side-menu for performing operations on the table.
The widths can be adjusted but I want to set an aesthetically-pleasing
default. I want the table to be larger than the side menu when the form is
loaded, something like a 75:25 ratio (currently the ratio is 50:50, which
makes the side-menu way too big). I've tried absolutely everything to get
the children to change size, but they simply won't do a thing. I've added
layouts, I have used absolute positioning, I've toyed around with many
different test values in each circumstance. I've looked at it over and
over again, but it's no use. No matter what I do, I can't seem to affect
the state of this widget or even figure out what the problem is.
shell.setLayout(new FillLayout()); //stretch the form to fill the window
sf = new SashForm(shell, SWT.NONE);
GridLayout gl = new GridLayout(2,false);
sf.setLayout(gl);
fillComp = new Composite(sf, SWT.NONE); //child 1: spreadsheet data
opComp = new Composite (sf, SWT.BORDER); //child 2: user operation panel
opComp.setLayout(new FillLayout());
GridData gd1 = new GridData(
2, //test values - could be 200000 and it wouldn't make a
difference
2 //
);
GridData gd2 = new GridData(
1, //test values
1 //
);
//gd1.horizontalSpan = 2; //blablabla
//gd2.horizontalSpan = 1; //all do nothing
//gd1.minimumWidth = 600; //tested a variety of variables, setting
them
//gd2.minimumWidth = 200; //to a variety of values
fillComp.setLayoutData(gd1);
opComp.setLayoutData(gd2);
sf.pack(); //these do nothing
fillComp.pack(); //
opComp.pack(); //
And I have a listener attached to fillComp, on event, it activates this:
try {
displayTable.setBounds(fillComp.getClientArea());
} catch (Exception ex) { }
The listener can be removed and it doesn't affect the width of the two
widgets.
I could post a half a dozen different code blocks, all of which have
failed to even make the layout change in the slightest. I could change the
parent's layout, but that just makes this layout much smaller but still
quite equally-unalterable.
Please provide insight if you can. I've read all the tutorials and code
snippets, but absolutely nothing makes a difference to this one particular
widget.
P.S. sf.setWeights(new int[] {3,1} ); gives an error.

No comments:

Post a Comment