Updating labels during runtime [message #465154] |
Wed, 07 December 2005 04:53 |
Eclipse User |
|
|
|
Originally posted by: mwilli.iastate.edu
I'm trying to change the image for a Label during runtime based on
input, and it doesn't change the image, but instead keeps the existing
image. Is there anything I could be forgetting to do to get this working?
Thanks, Mike
|
|
|
Re: Updating labels during runtime [message #465353 is a reply to message #465154] |
Fri, 09 December 2005 16:11 |
Veronika Irvine Messages: 1272 Registered: July 2009 |
Senior Member |
|
|
The following works for me:
public static void main (String [] args) {
Display display = new Display ();
final Image[] images = new Image[] {
display.getSystemImage(SWT.ICON_ERROR),
display.getSystemImage(SWT.ICON_INFORMATION),
display.getSystemImage(SWT.ICON_QUESTION),
display.getSystemImage(SWT.ICON_WARNING),
};
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
final Label l = new Label(shell, SWT.BORDER);
l.setText("Click button to change image");
Button b = new Button(shell, SWT.PUSH);
b.setText("change image");
b.addListener(SWT.Selection, new Listener() {
int index = 0;
public void handleEvent(Event e) {
l.setImage(images[index]);
index = (index + 1) % images.length;
}
});
shell.setSize(300, 300);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
"Mike Williams" <mwilli@iastate.edu> wrote in message
news:dn5psg$icc$1@news.eclipse.org...
> I'm trying to change the image for a Label during runtime based on input,
> and it doesn't change the image, but instead keeps the existing image. Is
> there anything I could be forgetting to do to get this working?
>
> Thanks, Mike
|
|
|
Powered by
FUDForum. Page generated in 0.03895 seconds