尝试在滚动的复合材料中创建2000个文本小部件(SWT),但仅创建了1092个

时间:2019-02-19 13:22:43

标签: java swt scrolledcomposite

我正在尝试在滚动的复合SWT中创建2000个文本框,但仅创建了1092个小部件。

我在代码中使用了网格布局,当我将布局更改为FillLayout时,显示的窗口小部件数量增加了,但再次受到限制。我没有看到其他任何问题。

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();

我想知道如何创建n个小部件以及这段代码在做什么错... Output Image

0 个答案:

没有答案