@@ -8290,8 +8290,10 @@ public void setBackground(Color color) {
82908290 customBackground = color != null && !this .insideSetEnableCall && !backgroundDisabled ;
82918291 background = color ;
82928292 super .setBackground (color );
8293- resetCache (0 , content .getLineCount ());
8294- setCaretLocations ();
8293+ if (content != null ) {
8294+ resetCache (0 , content .getLineCount ());
8295+ setCaretLocations ();
8296+ }
82958297 super .redraw ();
82968298}
82978299/**
@@ -8772,6 +8774,41 @@ public void setDragDetect (boolean dragDetect) {
87728774 checkWidget ();
87738775 this .dragDetect = dragDetect ;
87748776}
8777+
8778+ /**
8779+ * Applies foreground and background colors based on the control's state.
8780+ * Custom foreground and background settings are preserved and not overridden.
8781+ *
8782+ * @param enabled {@code true} if the control is enabled; {@code false} otherwise
8783+ * @param editable {@code true} if the control is editable; {@code false} otherwise
8784+ * @since 3.134
8785+ *
8786+ */
8787+ protected void updateColors (boolean enabled , boolean editable ) {
8788+ this .insideSetEnableCall = true ;
8789+ Display display = getDisplay ();
8790+ try {
8791+ if (enabled && editable ) {
8792+ if (!customBackground )
8793+ setBackground (display .getSystemColor (SWT .COLOR_LIST_BACKGROUND ));
8794+ if (!customForeground )
8795+ setForeground (display .getSystemColor (SWT .COLOR_LIST_FOREGROUND ));
8796+ } else if (!enabled ) {
8797+ if (!customBackground )
8798+ setBackground (display .getSystemColor (SWT .COLOR_TEXT_DISABLED_BACKGROUND ));
8799+ if (!customForeground )
8800+ setForeground (display .getSystemColor (SWT .COLOR_WIDGET_DISABLED_FOREGROUND ));
8801+ } else if (!editable ) {
8802+ if (!customBackground )
8803+ setBackground (display .getSystemColor (SWT .COLOR_TITLE_INACTIVE_BACKGROUND ));
8804+ if (!customForeground )
8805+ setForeground (display .getSystemColor (SWT .COLOR_GRAY ));
8806+ }
8807+ } finally {
8808+ this .insideSetEnableCall = false ;
8809+ }
8810+ }
8811+
87758812/**
87768813 * Sets whether the widget content can be edited.
87778814 *
@@ -8785,28 +8822,13 @@ public void setDragDetect (boolean dragDetect) {
87858822public void setEditable (boolean editable ) {
87868823 checkWidget ();
87878824 this .editable = editable ;
8825+ updateColors (this .enabled , this .editable );
87888826}
87898827@ Override
87908828public void setEnabled (boolean enabled ) {
87918829 super .setEnabled (enabled );
8792- Display display = getDisplay ();
87938830 this .enabled = enabled ;
8794- this .insideSetEnableCall = true ;
8795- try {
8796- if (enabled && editable ) {
8797- if (!customBackground ) setBackground (display .getSystemColor (SWT .COLOR_LIST_BACKGROUND ));
8798- if (!customForeground ) setForeground (display .getSystemColor (SWT .COLOR_LIST_FOREGROUND ));
8799- } else if (!enabled ) {
8800- if (!customBackground ) setBackground (display .getSystemColor (SWT .COLOR_TEXT_DISABLED_BACKGROUND ));
8801- if (!customForeground ) setForeground (display .getSystemColor (SWT .COLOR_WIDGET_DISABLED_FOREGROUND ));
8802- } else if (!editable ) {
8803- if (!customBackground ) setBackground (display .getSystemColor (SWT .COLOR_TEXT_DISABLED_BACKGROUND ));
8804- if (!customForeground ) setForeground (display .getSystemColor (SWT .COLOR_LIST_FOREGROUND ));
8805- }
8806- }
8807- finally {
8808- this .insideSetEnableCall = false ;
8809- }
8831+ updateColors (this .enabled , this .editable );
88108832}
88118833
88128834@ Override
@@ -8885,8 +8907,10 @@ public void setForeground(Color color) {
88858907 customForeground = color != null && !this .insideSetEnableCall && !foregroundDisabled ;
88868908 foreground = color ;
88878909 super .setForeground (color );
8888- resetCache (0 , content .getLineCount ());
8889- setCaretLocations ();
8910+ if (content != null ) {
8911+ resetCache (0 , content .getLineCount ());
8912+ setCaretLocations ();
8913+ }
88908914 super .redraw ();
88918915}
88928916/**
0 commit comments