Im doing a tutorial and i added a few labels myself to test it out and throw a few things around to get a better grip on it, and labellast.setLocation seems to just do nothing to labellast, the location of the label wont change…
Here is my source:
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(250, 350);
Label label1 = new Label(shell, SWT.BORDER);
label1.setText("Hello World!");
label1.setSize(100, 20);
label1.setLocation(30, 30);
Text text1 = new Text(shell, SWT.BORDER);
text1.setText("Type Here");
text1.setTextLimit(50);
text1.setBounds(10, 10, 200, 20);
text1.setLocation(30, 60);
Label hello = new Label(shell, SWT.BORDER);
hello.setText("type what the top line says.");
hello.setSize(190, 20);
hello.setLocation(30, 90);
Label sep1 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL
| SWT.SHADOW_IN);
sep1.setBounds(30, 60, 100, 120);
Label label2 = new Label(shell, SWT.NONE);
label2.setText("World Hello");
label2.setSize(100, 20);
label2.setLocation(30, 150);
Label sep2 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
sep2.setBounds(30, 120, 100, 20);
Label label3 = new Label(shell, SWT.NONE);
label3.setSize(100, 20);
label3.setLocation(30, 210);
label3.setBackground(new Color(display, 200, 111, 50));
label3.setText("World World.");
Text text2 = new Text(shell, SWT.NONE);
text2.setEchoChar('*');
text2.setBounds(10, 50, 200, 20);
text2.setText("Password");
text2.setLocation(30, 250);
text2.setEditable(false);
Label labellast = new Label(shell, SWT.NONE);
labellast.setLocation(30, 300);
labellast.setText("You cant edit that^^^");
labellast.setBounds(10, 50, 200, 20);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
The method
setBoundssets both the position and size.Get rid of the call to
setLocationand just usesetBounds:In your code you are calling
setLocationfirst, then later overriding the position when you callsetBoundswhich makes it look like you can’t change the location.