How is it possible to position text in an SWT Shell?
My problem is that I don't know which Layout to use. I've tried Row and Fill-Layout, but this won't work if I do it like text.setLocation(x,y)
.
Can anyone help me?
Join Stack Overflow to learn, share knowledge, and build your career.
How is it possible to position text in an SWT Shell?
My problem is that I don't know which Layout to use. I've tried Row and Fill-Layout, but this won't work if I do it like text.setLocation(x,y)
.
Can anyone help me?
Solved it.
If you use no Layout, put the elements you want in a SWT Group, you can position it free inside this group.
Group group = new Group(parent, SWT.NONE);
Text text = new Text(group, SWT.BORDER);
group.setSize(parent.getSize());
text.setLocation(parent.getSize().x/2, parent.getSize().y/2);
Will look like this:
Might be worth taking a look at FormLayout. Would go something like:
Group group = new Group(parent, SWT.NONE);
group.setLayout(new FormLayout());
Text text = new Text(group, SWT.BORDER);
text.setText("Text1");
FormData fd = new FormData();
fd.top = new FormAttachment(50,0);
fd.left = new FormAttachment(50,0);
text.setLayoutData(fd);
The FormAttachment class lets you specify both a percentage of the container width (50% in this case), and also a fixed offset(0).