Reputation: 99
How can I arrange Label
s on a canvas from its top left down and so on?
and if you can show me how to do that in a loop.
I tried to use GridData
, but I don't think I understand it that much.
GridData gd = new GridData(SWT.LEFT);
Label lbl = new Label(canvas, SWT.LEFT);
lbl.setText("A: ");
lbl.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
lbl.setLayoutData(gd);
Label lbl2 = new Label(c,SWT.TOP);
lbl.setText("B: ");
lbl.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
lbl2.setLayoutData(gd);
Upvotes: 0
Views: 60
Reputation: 36894
If you just want one column, use RowLayout
with SWT.VERTICAL
:
public static void main(String[] args)
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new RowLayout(SWT.VERTICAL));
shell.setText("StackOverflow");
for(int i = 0; i < 10; i++)
{
new Label(shell, SWT.NONE).setText("Label " + i);
}
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}
Looks like this:
Upvotes: 2
Reputation: 1
SWT.LEFT and SWT.TOP first of all, shouldn't that be the same or? second with array just loop trough the array and for each value create a label size/position is just (in %) 100/TOTAL * KEY (if KEY starts at 0 and goes to the highest)
Upvotes: 0