Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » [SOLVED] Expandable Text widget
[SOLVED] Expandable Text widget [message #548985] Fri, 23 July 2010 15:30 Go to next message
Konrad is currently offline KonradFriend
Messages: 3
Registered: July 2010
Junior Member
Hi!

I'm trying to make this Text widget:

new Text(box, SWT.MULTI  | SWT.WRAP | SWT.BORDER );


to expand as I enter new lines. Basically its height should grow to show all text inside it.

When I open editor with this Text, I see this:

http://dl.dropbox.com/u/8989748/tmp/expand1.png

So everything looks good. When I enter next line field does not grow and (what is the worst part) after playing around (fg. expanding second ExpandItem) container of this field eventually updates its height and it looks like this:

http://dl.dropbox.com/u/8989748/tmp/expand2.png

And this looks bad. I understand that I should somehow call `update` on Text and all its parents from ModifyListener (or make whole editor to recalculate heights and repaint). I had no luck playing with update/repaint so far, please help.

Cheers,
Konrad

ps. whole thing is on BorderLayouts, Text widgets are inside ExpandBar widget.

[Updated on: Wed, 28 July 2010 19:57]

Report message to a moderator

Re: Expandable Text widget [message #549196 is a reply to message #548985] Mon, 26 July 2010 03:51 Go to previous messageGo to next message
karthikeyan  is currently offline karthikeyan Friend
Messages: 6
Registered: July 2009
Junior Member
plz upload the image.....

--
Karthikeyan
icon5.gif  Re: Expandable Text widget [message #549924 is a reply to message #548985] Wed, 28 July 2010 13:41 Go to previous messageGo to next message
Konrad is currently offline KonradFriend
Messages: 3
Registered: July 2010
Junior Member
I have no idea how to upload them here. I can see 'File Attachments' menu below, but there is no button/upload field.

In fact, images are not so important, question is: how can I force my mulit-line Text field to change height after entering a new line. Text fields do that automatically when you reload editor, I just need to force this behavior while typing.
Re: Expandable Text widget [message #550008 is a reply to message #549924] Wed, 28 July 2010 17:29 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Sometimes images in messages only appear when viewed in the eclipse forums
but do not appear when read through a reader like Outlook.

A similar question to this has been asked before, so I've created a snippet
that demonstrates updating an ExpandItem's height in response to changes in
its contained Text. See
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet343.java?view=co .

HTH,
Grant


"Konrad" <kdzwinel@gmail.com> wrote in message
news:i2pc1t$85f$1@build.eclipse.org...
>I have no idea how to upload them here. I can see 'File Attachments' menu
>below, but there is no button/upload field.
>
> In fact, images are not so important, question is: how can I force my
> mulit-line Text field to change height after entering a new line. Text
> fields do that automatically when you reload editor, I just need to force
> this behavior while typing.
Re: Expandable Text widget [message #550035 is a reply to message #550008] Wed, 28 July 2010 19:56 Go to previous message
Konrad is currently offline KonradFriend
Messages: 3
Registered: July 2010
Junior Member
Thank you very much. I based my code on yours and it works perfectly.

I ended up with this (maybe It will help someone):

text.addListener(SWT.Modify, new Listener() {
  public void handleEvent(Event event) {
     //compute new Text field size
    Point size = text.computeSize(text.getSize().x, SWT.DEFAULT);

    //compute the difference between new and old Text field height
    int diff = size.y - text.getSize().y;
					
    if( expandItem != null )
    {
       //add diff to ExpandItems' height
      expandItem.setHeight(expandItem.getHeight() + diff);
    }
					
     //'reset' the layout if you are using one
    box.getParent().layout();
  }
});


Calling layout() makes most of the work, the only problem is with ExpandItem. It doesn't change its height automatically (I don't have any idea why) - you have to set it up every time in the modify listener.
Previous Topic:FocusListener vs IPartListener
Next Topic:Rich Text Editor with XML model
Goto Forum:
  


Current Time: Fri Apr 26 15:24:31 GMT 2024

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

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

Back to the top