Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Editable Text to fill scrolled composite, but not expand it?(Getting an editable Text with WRAP to fill a resizable scrolled composite)
Editable Text to fill scrolled composite, but not expand it? [message #492416] Tue, 20 October 2009 12:03 Go to next message
Torbjørn G. Dahle is currently offline Torbjørn G. DahleFriend
Messages: 20
Registered: July 2009
Junior Member
I have a Text inside the body of a ScrolledForm (I'm posting here since I assume it has to do with ScrolledComposite). I want the Text to always fit the width of the form when its resized, and wrap its contents.

The Text has SWT.WRAP, and a grid layout with SWT.FILL and grabExcess = true in both directions.

If I set a text value with a long line, the Text doesn't wrap within the width of the form, but expand to fit the unwrapped line. To get the behavior I want I've added a resize listener on the form that calculates a new widthHint of the Text and runs layout and reflow. This leads to a bunch of messy code and seems unnecessary. Is there a proper way of getting the behaviour I'm after?
Re: Editable Text to fill scrolled composite, but not expand it? [message #492436 is a reply to message #492416] Tue, 20 October 2009 12:48 Go to previous messageGo to next message
Torbjørn G. Dahle is currently offline Torbjørn G. DahleFriend
Messages: 20
Registered: July 2009
Junior Member
By looking at the Label source code, it appears that SWT.WRAP is only used for computing the label size if widthHint is set. Does this mean that the only way to get the Label to dynamically wrap as its parent is resized is to manually calculate a new widhHint, set it and run layout again?
Re: Editable Text to fill scrolled composite, but not expand it? [message #492773 is a reply to message #492436] Wed, 21 October 2009 16:34 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
Hi,

The Label/Text has to be constrained by some means so that it knows where to
wrap, but setting a widthHint is not the only way to do this. If the
ScrolledComposite is using a GridLayout and the Label's layout data
specifies to fill horizontally then the Label should be auto-resized to
match its parent, and this is where it will wrap. Your case is probably
more complex than the snippet below, but hopefully this will provide some
clues...

public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
ScrolledComposite c1 = new ScrolledComposite(shell, SWT.H_SCROLL |
SWT.V_SCROLL);
c1.setLayout(new GridLayout());
Text text = new Text(c1, SWT.MULTI | SWT.WRAP | SWT.BORDER);
text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL,
GridData.BEGINNING, true, false));
for (int i = 0; i < 999; i++) {
text.append(" asdf" + i);
}
c1.setContent(text);
c1.setAlwaysShowScrollBars(true);
c1.setExpandHorizontal(true);
c1.setExpandVertical(true);
c1.setMinSize(300, 300);
shell.setSize(300, 300);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}

HTH,
Grant


"Torbj" <tgdahle@origin.no> wrote in message
news:hbkbi2$2g7$1@build.eclipse.org...
> By looking at the Label source code, it appears that SWT.WRAP is only used
for computing the label size if widthHint is set. Does this mean that the
only way to get the Label to dynamically wrap as its parent is resized is to
manually calculate a new widhHint, set it and run layout again?
Re: Editable Text to fill scrolled composite, but not expand it? [message #492910 is a reply to message #492773] Thu, 22 October 2009 10:41 Go to previous messageGo to next message
Torbjørn G. Dahle is currently offline Torbjørn G. DahleFriend
Messages: 20
Registered: July 2009
Junior Member
Thanks, your example works just the way I want my view to. Unfortunately, it seems the problem lies in ScrolledForm specifically. If I change your code from ScrolledComposite to ScrolledForm, and put the text in the form's body, it stops wrapping.

I guess this means the SWT forum is no longer the place for this problem. Should I take it to the JFace one, or is there some other forum for these form components?
Re: Editable Text to fill scrolled composite, but not expand it? [message #492953 is a reply to message #492910] Thu, 22 October 2009 13:27 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
The group you want is eclipse.platform.ua .

Grant


"Torbj" <tgdahle@origin.no> wrote in message
news:hbpcs9$h4$1@build.eclipse.org...
> Thanks, your example works just the way I want my view to. Unfortunately,
it seems the problem lies in ScrolledForm specifically. If I change your
code from ScrolledComposite to ScrolledForm, and put the text in the form's
body, it stops wrapping.
>
> I guess this means the SWT forum is no longer the place for this problem.
Should I take it to the JFace one, or is there some other forum for these
form components?
Previous Topic:Drawing focus ring on mac
Next Topic:other IE process be killed when execute js "window.open"??
Goto Forum:
  


Current Time: Mon Aug 26 01:01:00 GMT 2019

Powered by FUDForum. Page generated in 0.02076 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top