Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Automatically resize multi-line Text widget to match # of rows
Automatically resize multi-line Text widget to match # of rows [message #532932] Tue, 11 May 2010 15:26 Go to next message
Misha Koshelev is currently offline Misha KoshelevFriend
Messages: 31
Registered: May 2010
Member
Dear All:

I am using the following code, which seems to work on Linux amd64, but not on Windows (it works, but the window seems to get moved from the top-left corner).

Any ideas?

Is there a proper way to do this?

Thank you
Misha

	javascript.addListener(SWT.Modify,new Listener() {
		protected int lines=0;
		public void handleEvent(Event e) {
		    int newlines=javascript.getLineCount();
		    if (newlines>10) {
			newlines=10;
		    }
		    if (newlines!=lines) {
			lines=newlines;
			((GridData)javascript.getLayoutData()).heightHint=javascript.getLineCount()*javascript.getLineHeight();
			getShell().pack();
		    }
		}
	    });
Re: Automatically resize multi-line Text widget to match # of rows [message #533341 is a reply to message #532932] Thu, 13 May 2010 13:03 Go to previous messageGo to next message
Praveen  is currently offline Praveen Friend
Messages: 86
Registered: July 2009
Member
I think you are on the right path. At the moment, I'm not sure of any
other ways of achieving this. However, the provided snippet does not
required to set heightHint as pack() takes care of computing and setting
the minimum size required for the text widget. So, the snippet can be
optimized to -

text.addListener(SWT.Modify,new Listener() {
protected int lines=0;
public void handleEvent(Event e) {
int newlines=text.getLineCount();
if (newlines>10) {
newlines=10;
} else if (newlines!=lines) {
lines=newlines;
text.getShell().pack();
}
}
});
Re: Automatically resize multi-line Text widget to match # of rows [message #533371 is a reply to message #533341] Thu, 13 May 2010 15:00 Go to previous message
Misha Koshelev is currently offline Misha KoshelevFriend
Messages: 31
Registered: May 2010
Member
Ah thank you so much. Will try

Misha
Previous Topic:Remove PaintListener in SWT
Next Topic:Dotted line missing on focused Radio button and List
Goto Forum:
  


Current Time: Thu Apr 18 01:57:21 GMT 2024

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

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

Back to the top