Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Layout not based on content of control
| |
Re: Layout not based on content of control [message #498944 is a reply to message #498939] |
Thu, 19 November 2009 10:16 |
JD Messages: 3 Registered: September 2009 |
Junior Member |
|
|
Tom Schindl wrote on Thu, 19 November 2009 04:54 | Probably using a FormLayout might help?
Tom
|
Thanks.
From a quick look into the JavaDoc, I think not, since there is nothing that would prevent the Text from growing vertically in the rest of the Form, so the Text would still be the dominant control.
On another note, I'd like to prevent exchanging the layout algorithm, since it would affect quite large portions of the code.
In the meantime I found a sort of workaround here in Example 4.
Basically you set the size hints to what they would be for the empty control.
It works in my case, but I'm, still looking for a proper way to do this, as the workaround does not work in cases, where the content is assigned before the layout data.
|
|
|
Re: Layout not based on content of control [message #499014 is a reply to message #498944] |
Thu, 19 November 2009 14:37 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
Hi,
Setting a widthHint and/or heightHint in the control's GridData is the
proper way to specify a control size that's != its preferred size. The
approach that you listed in your first message sounded right. I don't know
much about ScrolledForm and Section since they come from ui forms, maybe
they're doing something to not consider your set GridDatas? Are you able to
provide a reproducable case that shows your problem (ideal template:
http://www.eclipse.org/swt/faq.php#whatisasnippet )?
Regarding the workaround, you can determine the size of an empty Text at any
time with "Text text = new Text(parent, style); Point size =
text.computeSize(SWT.DEFAULT,SWT.DEFAULT);text.dispose();".
Grant
"JD" <duschl@creamteam.de> wrote in message
news:he35tr$l8d$1@build.eclipse.org...
> Tom Schindl wrote on Thu, 19 November 2009 04:54
> > Probably using a FormLayout might help?
> >
> > Tom
>
>
> Thanks.
>
> From a quick look into the JavaDoc, I think not, since there is nothing
that would prevent the Text from growing vertically in the rest of the Form,
so the Text would still be the dominant control.
>
> On another note, I'd like to prevent exchanging the layout algorithm,
since it would affect quite large portions of the code.
>
> In the meantime I found a sort of workaround
http://help.eclipse.org/galileo/topic/org.eclipse.platform.d oc.isv/reference/api/org/eclipse/jface/layout/GridDataFactor y.html
in Example 4.
> Basically you set the size hints to what they would be for the empty
control.
> It works in my case, but I'm, still looking for a proper way to do this,
as the workaround does not work in cases, where the content is assigned
before the layout data.
|
|
| |
Re: Layout not based on content of control [message #499260 is a reply to message #499189] |
Fri, 20 November 2009 15:24 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
The snippet below is based on the one from the forms article. It updates
the Link's GridData's width hint, and therefore where it wraps, based on
size changes in its parent.
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.forms.widgets.*;
public class Main0 {
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(200, 200, 400, 400);
shell.setLayout(new FillLayout());
FormToolkit toolkit = new FormToolkit(shell.getDisplay());
Form form = toolkit.createForm(shell);
form.setText("Hello, Eclipse Forms");
GridLayout layout = new GridLayout();
form.getBody().setLayout(layout);
final Hyperlink link = toolkit.createHyperlink(form.getBody(), "",
SWT.WRAP);
link.setText("This is an example of a form that is much longer and will
need to wrap. " +
"This is an example of a form that is much longer and will need to
wrap.");
link.setLayoutData(new GridData());
link.getParent().addListener(SWT.Resize, new Listener() { // <----
public void handleEvent(Event event) {
Rectangle rect = link.getParent().getClientArea();
((GridData)link.getLayoutData()).widthHint = rect.width;
link.getParent().layout();
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
shell.dispose();
display.dispose();
}
}
HTH,
Grant
"JD" <duschl@creamteam.de> wrote in message
news:he5sj5$sui$1@build.eclipse.org...
> Hi Grant,
>
> There already is reproducing code here (well sort of):
> http://www.eclipse.org/articles/Article-Forms/article.html
>
http://209.85.129.132/search?q=cache:cwaR0Mind7sJ:www.eclips e.org/articles/Article-Forms/article.html+inurl:http://www.e clipse.org/articles/Article-Form
s/article.html+%22Although+we+instructed+the+control+to+wrap ,+it+did+not+mat
ter+because+GridLayout+requires+that+a+control+return+its+si ze+in+isolation%
22&cd=1&hl=en&ct=clnk
>
> I think I can put together a snipped next week though, if you like.
>
> Grant Gayed wrote on Thu, 19 November 2009 09:37
> > Hi,
> >
> > Setting a widthHint and/or heightHint in the control's GridData is the
> > proper way to specify a control size that's != its preferred size. The
> > approach that you listed in your first message sounded right. I don't
know
> > much about ScrolledForm and Section since they come from ui forms, maybe
> > they're doing something to not consider your set GridDatas? Are you
able to
> > provide a reproducable case that shows your problem (ideal template:
> > http://www.eclipse.org/swt/faq.php#whatisasnippet )?
> >
> > Regarding the workaround, you can determine the size of an empty Text at
any
> > time with "Text text = new Text(parent, style); Point size =
> > text.computeSize(SWT.DEFAULT,SWT.DEFAULT);text.dispose();".
> >
> > Grant
>
>
|
|
|
Goto Forum:
Current Time: Tue Sep 24 04:52:19 GMT 2024
Powered by FUDForum. Page generated in 0.03985 seconds
|