[SOLVED] Expandable Text widget [message #548985] |
Fri, 23 July 2010 15:30 |
|
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:
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:
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 #549924 is a reply to message #548985] |
Wed, 28 July 2010 13:41 |
|
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 |
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.02986 seconds