0

I am trying to create 2000 text boxes inside a scrolled composite SWT but only 1092 widgets get created.

I am using grid layout in my code and when i change the layout to FillLayout the number of widgets that get displayed gets increased but again its limited. I don't see any other problem.

Display display = new Display();
Shell shell = new Shell();
shell.setText("StackOverflow");
shell.setLayout(new GridLayout(1, false));

Group first = new Group(shell, SWT.NONE);
first.setText("Group 1");
first.setLayout(new GridLayout(1, false));
GridData firstData = new GridData(SWT.FILL, SWT.FILL, true, false);
firstData.heightHint = 400;
first.setLayoutData(firstData);

ScrolledComposite firstScroll = new ScrolledComposite(first, SWT.V_SCROLL);
firstScroll.setLayout(new GridLayout(1, false));
firstScroll.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

Composite firstContent = new Composite(firstScroll, SWT.NONE);
firstContent.setLayout(new GridLayout(1, false));
firstContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

for (int i = 0; i < 2000; i++) {
  Text text = new Text(firstContent, SWT.BORDER);
  text.setText(i + "");
  text.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
}

firstScroll.setContent(firstContent);
firstScroll.setExpandHorizontal(true);
firstScroll.setExpandVertical(true);
firstScroll.setMinSize(firstContent.computeSize(SWT.DEFAULT, SWT.DEFAULT));

shell.pack();
shell.setSize(400, shell.getSize().y);
shell.open();

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

I would like to know how to create n widgets and what am i doing wrong in this code... Output Image

A.G
  • 3
  • 6
  • 1
    On some platforms (Windows for example) controls have a maximum size, you may be hitting that. A Table or TableViewer with its built in scrolling won't have that problem. See [here](https://www.eclipse.org/forums/index.php/t/121005/) for a similar discussion. – greg-449 Feb 19 '19 at 13:48
  • Just checking and this code runs fine on macOS so this is almost certainly a control size limit. – greg-449 Feb 19 '19 at 13:59
  • @greg-449 Thanks for your response, will try using scroll bars and will see whether that solves the problem. – A.G Feb 19 '19 at 14:16

0 Answers0