Trying to create 2000 text widgets(SWT) inside a scrolled composite but only 1092 get created

40 Views Asked by At

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

0

There are 0 best solutions below