public class ImageViewer extends ViewPart {
String text;
public ImageViewer() {}
public void setA(String val) {
String text=val;
}
@Override
public void createPartControl(Composite parent) {
Label labelMsg1 = new Label(parent, SWT.NONE);
labelMsg1.setText("Hello");
}
public void setFocus() {}
}
I want "Hello"
to be removed and a value "val"
to be printed on my label. "val"
is coming from a different view and is passed as a method. How can I do this?
You need to call the setText
of your object, but it is only locally known. You need to make it a member and then you can do it:
public class ImageViewer extends ViewPart {
String text;
protected Label labelMsg1;
public ImageViewer() {}
public void setA(String val) {
String text=val;
labelMsg1.setText(val);
}
@Override
public void createPartControl(Composite parent) {
if (labelMsg1 == null) {
labelMsg1 = new Label(parent, SWT.NONE);
labelMsg1.setText("Hello");
}
}
public void setFocus() {}
}
Also, you want to set the text of your Label
object, not its value.