From f3bce708e5da39d57d89130d65bd0324ff79290d Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Tue, 15 Sep 2026 16:19:03 +0200 Subject: [PATCH] Clear the CTabFolder background gradient in setBackground(Color) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CTabFolder.setBackground(Color) kept a gradient set earlier, so the folder continued to paint gradient images behind the controls in its tab row. Controls without their own colour showed the stale gradient while the others showed the solid colour, which gave toolbar buttons of an inactive part stack mismatched backgrounds. Assisted-by: multiple AI agents and layers of automated tooling 🤖 --- .../org/eclipse/swt/custom/CTabFolder.java | 10 +++++++++- ...est_org_eclipse_swt_custom_CTabFolder.java | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java index 418da72a628..c89e06e90a2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java @@ -2379,9 +2379,16 @@ public void reskin(int flags) { } } +/** + * Sets the background color of the unselected tabs, clearing any background + * gradient set by {@link #setBackground(Color[], int[], boolean)}. + */ @Override public void setBackground (Color color) { super.setBackground(color); + gradientColors = null; + gradientPercents = null; + gradientVertical = false; updateBkImages(true); redraw(); } @@ -2501,7 +2508,8 @@ public void setBackground(Color[] colors, int[] percents, boolean vertical) { gradientPercents[i] = percents[i]; } gradientVertical = vertical; - setBackground(gradientColors[gradientColors.length-1]); + super.setBackground(gradientColors[gradientColors.length-1]); + updateBkImages(true); } // Refresh with the new settings diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java index d0a0bafa065..6e9cbae3fb1 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java @@ -1208,6 +1208,26 @@ public void test_moveItem_sameIndexIsNoOp() { assertEquals(2, ctabFolder.getSelectionIndex()); } +@Test +public void test_setBackgroundColorClearsGradient() { + createTabFolder(null); + Composite topRight = new Composite(ctabFolder, SWT.NONE); + topRight.setLayout(new FixedSizeLayout(16, 8)); + ctabFolder.setTopRight(topRight, SWT.RIGHT); + shell.setSize(400, 300); + shell.layout(true, true); + Color red = shell.getDisplay().getSystemColor(SWT.COLOR_RED); + Color blue = shell.getDisplay().getSystemColor(SWT.COLOR_BLUE); + + ctabFolder.setBackground(new Color[] { red, blue }, new int[] { 100 }, true); + assertNotNull(topRight.getBackgroundImage(), "gradient must be handed to the top right control"); + + ctabFolder.setBackground(blue); + assertNull(topRight.getBackgroundImage(), "solid background must replace the gradient"); + assertEquals(blue, topRight.getBackground()); + assertEquals(blue, ctabFolder.getBackground()); +} + @Test public void test_moveItem_errorCases() { createTabFolder(null, 3);