Reputation: 606
When trying to add a lot of labels on to a Composite that is contained in a ScrolledComposite after a certain number (1638) for me, it just seems to give up and stop drawing the components after it. Is this a hard limit on a number of things that can be displayed or something I'm doing wrong.
This also happens if I just add one label with 2000 lines of text in.
public class LoadsOfLabelsTestDialog extends Dialog
{
List<Label> displaylabels = new ArrayList<>();
Composite content, list;
ScrolledComposite scroll;
public LoadsOfLabelsTestDialog(Shell parentShell)
{
super(parentShell);
}
@Override
protected void configureShell(Shell shell)
{
super.configureShell(shell);
shell.setSize(new Point(700, 500));
shell.setText("FML"); //$NON-NLS-1$
}
@Override
public Control createDialogArea(final Composite comp)
{
content = (Composite) super.createDialogArea(comp);
content.setLayout(new GridLayout(1, false));
content.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Button set1 = new Button(content, SWT.PUSH);
set1.setText("Display List 1");
set1.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
List<String> rows = new ArrayList<>();
for (int i = 0; i < 2000; i++) {
rows.add(i +" row");
}
updateList(rows);
}
});
scroll = new ScrolledComposite(content, SWT.V_SCROLL);
list = new Composite(scroll, SWT.NONE);
list.setLayout(new GridLayout(1, true));
scroll.setContent(list);
scroll.setExpandHorizontal(true);
scroll.setExpandVertical(true);
scroll.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
new Label(content, SWT.HORIZONTAL | SWT.SEPARATOR);
setScrollSize();
return content;
}
private void setScrollSize() {
scroll.setMinSize(list.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
private void updateList(List<String> rows) {
if (this.displaylabels == null) {
this.displaylabels = new ArrayList<>();
}
for (Label l : displaylabels) {
l.dispose();
}
this.displaylabels.clear();
for (String item : rows) {
addListLabel(item);
}
content.layout(true, true);
setScrollSize();
}
private void addListLabel(String whoText) {
Label a = new Label(list, SWT.NONE);
a.setText(whoText);
this.displaylabels.add(a);
}
public static void main(String[] args)
{
Display d = new Display();
Shell s = new Shell();
LoadsOfLabelsTestDialog fml = new LoadsOfLabelsTestDialog(s);
fml.open();
}
}
Upvotes: 0
Views: 49
Reputation: 20985
You hit a hard limit, probably the maximum size of a control. While this limit may differ slightly on other platforms, you can't size a control arbitrarily.
As @greg-449 suggested, prefer using a Table
. If the content per table row is more than just an image and text, you can add a paint listener to draw the row contents yourself.
Upvotes: 1