Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Updating labels during runtime
Updating labels during runtime [message #465154] Wed, 07 December 2005 04:53 Go to next message
Eclipse UserFriend
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 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
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
Previous Topic:urgent - EXCEPTION_ACCESS_VIOLATION
Next Topic:SWT application port to PocketPC
Goto Forum:
  


Current Time: Thu Apr 25 20:15:09 GMT 2024

Powered by FUDForum. Page generated in 0.02746 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top