1

I have a StyledText widget (SWT) inside a ScrolledComposite that should display the content of a log file. Unfortunately the log file has thousands of lines in it so that I came to the point where the widget cuts off the text after ~ 2200 lines.

I found this post that refers to this report that states that there is a height limitation for widgets in windows and my theory is that I have reached that limit.

My question is how I can deal with this. What is the workaround for displaying text with that many lines in it?

EDIT:
I found out that this does only happen, if I use the StyledText inside a ScrolledComposite. If I use the plain StyledText there is no problem.

Here's the code to reproduce:

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class StyledTextLimit {

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());

        ScrolledComposite scrollComp = new ScrolledComposite(shell,
                SWT.H_SCROLL | SWT.V_SCROLL);

        StyledText text = new StyledText(scrollComp, SWT.NONE);
        text.setSize(100, 500);

        scrollComp.setContent(text);
        scrollComp.setExpandHorizontal(true);
        scrollComp.setExpandVertical(true);

        StringBuilder builder = new StringBuilder();

        for (int i = 0; i < 5000; i++) {
            builder.append(i);

            builder.append(" ");

            for (int j = 'a'; j < 'a' + 200; j++) {
                builder.append((char) j);
            }

            builder.append("\n");
        }

        text.setText(builder.toString().trim());

        scrollComp.setMinSize(text.computeSize(SWT.DEFAULT, SWT.DEFAULT));


        // shell.pack();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }

}
Community
  • 1
  • 1
Raven
  • 2,951
  • 2
  • 26
  • 42

2 Answers2

0

I don't see a need to wrap the StyledText into a ScrolledComposite. The StyledText shows scrollbars on its own when necessary.

I suggest using the StyledText without a ScrolledComposite.

The StyledText certainly also has a limit on what text it is capable to hold. This limit, however, should be much higher than 2200 lines. If StyledText still overflows, then you'll have to truncate the log to be shown.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
  • The problem is that I have a line counter to the left of the `StyledText` as a `Label` so that I think I still need the `ScrolledComposite`... – Raven Sep 13 '16 at 13:03
  • 1
    If you don't mind the dependency on `org.eclipse.jface.text`, you could use a `SourceViewer` which wraps a `StyledText` and allows showing _rulers_ with line numbers. – Rüdiger Herrmann Sep 13 '16 at 13:14
  • Okay as you can see in my edited question I found out that the problem seems to be the `ScrolledComposite` and not the `StyledText`... – Raven Sep 13 '16 at 13:15
  • For anybody with the same problem: I used [this](http://stackoverflow.com/questions/11057442/java-swt-show-line-numbers-for-styledtext) solution to add the line numbers as the `SourceViewer` was too complicated for my purpose – Raven Sep 13 '16 at 14:13
0

Although @Rüdiger Herrmann helped me fixing my problem I still feel that I should help those who might come to the same problem as I did without the possibility of getting rid of the ScrolledComposite.

Therefore I want to link this post that deals with the ScrolledComposite problem.

Community
  • 1
  • 1
Raven
  • 2,951
  • 2
  • 26
  • 42