Hello all !
I found a strange behaviour of the « Text »
widget today :
When it’s not editable (setEditable(false)),
the background color of the widget becomes gray (at least on windows, which is
the OS I use).
Then if I query this background color, it returns the
“editable” background color : white (instead of gray !)
Maybe this is the expected behaviour, but then, how can
I properly get the “non-editable” background color ?
Here is a snippet demonstrating the problem :
import org.eclipse.swt.SWT;
import
org.eclipse.swt.layout.RowLayout;
import
org.eclipse.swt.widgets.Display;
import
org.eclipse.swt.widgets.Label;
import
org.eclipse.swt.widgets.Shell;
import
org.eclipse.swt.widgets.Text;
public class BackgroundTest
{
public static void
main (String [] args) {
Display display
= new Display();
Shell shell =
new Shell(display);
RowLayout layout
= new RowLayout();
layout.wrap =
true;
shell.setLayout(layout);
// Shows a
simple editable text widget
Text
textE = new Text (shell, SWT.BORDER);
textE.setText
("editable");
// Shows a label
with background color set to the text’s background color
Label labelE =
new Label (shell, SWT.BORDER);
labelE.setText("editable\nbackground");
labelE.setBackground(textE.getBackground());
// Shows a
simple non-editable text widget
Text textNE =
new Text (shell, SWT.BORDER);
textNE.setEditable(false);
textNE.setText
("non-editable");
// Shows a label
with background color set to the non-editable text’s background color
Label labelNE =
new Label (shell, SWT.BORDER);
labelNE.setText("non-editable\nbackground");
labelNE.setBackground(textNE.getBackground());
// THIS LABEL’S
BACKGROUND COLOR IS WHITE !
// IT SHOULD BE
GRAY !!!!
shell.pack();
shell.open();
while
(!shell.isDisposed()) {
if
(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Thanks in advance for your help !
Stephane