[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[platform-swt-dev] Button image missing when Button.setEnabled(false)
|
My Button image disappears when I call Button.setEnabled(false). I created
two images one for when my Button is enabled and one for when it's disabled
the enabled image and Button work fine but when the button is disabled all I
see is a dark gray square in the center of the Button. I have tried setting
the disabled image before and after the call to Button.setEnabled(false) but
the behavior is unchanged. I looked to see if there is a bug report but
could not fine one. Does anyone know if this is a SWT Windows only bug or is
it the same on all platforms? I am using swt-win32-2135.dll in Windows 2000.
Below is a code snippet to reproduce this problem. Note you must supply the
two images (images/Open24.gif, images/OpenDisabled24.gif) because I did not
know if attachments are accepted by the mailing list.
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.graphics.*;
import java.io.InputStream;
public class ButtonExample
{
private Button disableButton;
private Button imageButton;
private Display display;
private Shell shell;
private Image enabled;
private Image disabled;
public ButtonExample() {
display = new Display ();
shell = new Shell (display);
imageButton = new Button (shell, SWT.PUSH);
enabled = new Image(display,
getImageResourceAsStream("images/Open24.gif"));
disabled = new Image(display,
getImageResourceAsStream("images/OpenDisabled24.gif"));
imageButton.setImage(enabled);
disableButton = new Button (shell, SWT.PUSH);
disableButton.setText ("Disable");
shell.setDefaultButton (disableButton);
shell.setLayout (new RowLayout ());
disableButton.addSelectionListener(new
org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent
e) {
if (imageButton.getEnabled()) {
imageButton.setImage(disabled);
imageButton.setEnabled(false);
imageButton.setImage(disabled);
disableButton.setText ("Enable");
}
else {
imageButton.setImage(enabled);
imageButton.setEnabled(true);
disableButton.setText ("Disable");
}
}
});
shell.pack ();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
private InputStream getImageResourceAsStream(String name) {
return getClass().getResourceAsStream("/" + name);
}
public static void main(String[] args) {
try {
new ButtonExample();
}
catch (Throwable e) {
e.printStackTrace();
}
}
}