Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Text background color


That behavior is platform specific.  There is no API in Windows to query that color from the operating system.  By observation, Windows is using COLOR_3DFACE which maps to the SWT system color, SWT.COLOR_WIDGET_BACKGROUND.



Stéphane WASSERHARDT <stephane.wasserhardt@xxxxxxxxxxxx>
Sent by: platform-swt-dev-bounces@xxxxxxxxxxx

10/04/2005 04:53 AM

Please respond to
"Eclipse Platform SWT component developers list."

To
"SWT" <platform-swt-dev@xxxxxxxxxxx>
cc
Subject
[platform-swt-dev] Text background color





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_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev


Back to the top