[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Re: StyledText and Scrollbar Position Problem
|
This looks like a bug, so I've logged
https://bugs.eclipse.org/bugs/show_bug.cgi?id=164120 . If you're able to
set the selection after the shell is open then this should work better for
you.
Grnt
"Mirko Stocker" <me@xxxxxxxx> wrote in message
news:eiplm5$9d5$1@xxxxxxxxxxxxxxxxxxxx
> Hi!
>
> I have a styledtext widget, fill it with some text and scroll to a
scpecific
> position, using setSelection. Now the problem is: the widget scrolls, but
> the scrollbar is at the wrong position.
>
> This is the code I used to test it:
>
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.custom.StyledText;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Dialog;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
>
> public class StyledTextTest extends Dialog {
>
> public static void main(String[] args) {
> Display display = Display.getDefault();
> Shell shell = new Shell(display);
> StyledTextTest inst = new StyledTextTest(shell, SWT.NULL);
> inst.open();
> }
>
> public StyledTextTest(Shell parent, int style) {
> super(parent, style);
> }
>
> public void open() {
> Shell parent = getParent();
> Shell dialogShell = new Shell(parent, SWT.DIALOG_TRIM);
>
> GridLayout dialogShellLayout = new GridLayout();
> GridData styledTextLData = new GridData();
> styledTextLData.grabExcessVerticalSpace = true;
> styledTextLData.grabExcessHorizontalSpace = true;
> styledTextLData.horizontalAlignment = GridData.FILL;
> styledTextLData.verticalAlignment = GridData.FILL;
>
> dialogShell.setLayout(dialogShellLayout);
> StyledText styledText = new StyledText(dialogShell,
> SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
> styledText.setLayoutData(styledTextLData);
>
> StringBuilder source = new StringBuilder();
>
> for(int i = 0; i < 100; i++) {
> source.append(i);
> source.append(". line\n");
> }
>
> styledText.setText(source.toString());
> styledText.setSelection(200, 210);
>
> dialogShell.setSize(200, 200);
> dialogShell.open();
> Display display = dialogShell.getDisplay();
> while (!dialogShell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> }
> }
>
> Does anybody have an Idea how to handle this correctly?
>
> Thanks a lot!
>
> Mirko
>