Text preferred size ignores trailing line feed [message #546005] |
Fri, 09 July 2010 16:52  |
Eclipse User |
|
|
|
I have a Shell that contains a single Text control. I want to resize the shell when I type in the Text control, so that it grows and shrinks as necessary to show the text content.
Here is my code:
package com.smartbear.test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;
public class TextResizeTest {
public static void main (String [] args) {
Display display = new Display ();
final Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
final Text text = new Text (shell, SWT.WRAP | SWT.MULTI);
text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
shell.pack();
}
});
shell.pack ();
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
This works if you type characters in the Text. If you insert a line feed in to the middle of some Text it grows vertically as appropriate.
However - if you append a line feed to the *end* of the Text, the Shell doesn't grow - instead the top line of Text is scrolled out of view.
It seems like Text.computeSize(SWT.DEFAULT, SWT.DEFAULT, true) ignores trailing line feeds? How can I get this to work the way I want?
Note I am running on Windows XP, Eclipse 3.6.
Thanks,
Roy
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04949 seconds