Skip to content

Conversation

ShahzaibIbrahim
Copy link
Contributor

Since Windows 7, the sort indicator in tree columns is rendered above the column header text, whereas in Windows XP it was placed next to the text. The original SWT implementation added extra pixels (SORT_WIDTH) to the column width to make space for the indicator.

In Windows XP, the indicator was next to the line, where the logic probably originated from. See,

image

From Windows 7 onwards, the sort indicator is on top like this,

image

Copy link
Contributor

github-actions bot commented Sep 2, 2025

Test Results

   546 files  ±0     546 suites  ±0   32m 9s ⏱️ -8s
 4 431 tests ±0   4 414 ✅ ±0   17 💤 ±0  0 ❌ ±0 
16 764 runs  ±0  16 637 ✅ ±0  127 💤 ±0  0 ❌ ±0 

Results for commit c3b03fe. ± Comparison against base commit f858239.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@BeckerWdf BeckerWdf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a code review and the changes look good to me.
As I am on macOS I cannot test the changes

@arunjose696
Copy link
Contributor

@ShahzaibIbrahim is there some snippet to test this change?

@arunjose696
Copy link
Contributor

arunjose696 commented Sep 9, 2025

I have tested the changes with the below snippet, the changes look good, without this change the column header is cropped of as in the left image and with this the full header is visible. So changes LGTM.

TreeColumnImageHeaderExample (Code)

package org.eclipse.swt.snippets;

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class TreeColumnImageHeaderExample {

    public static void main(String[] args) {
        final Display display = new Display();
        System.setProperty("swt.autoScale", "quarter");
        System.setProperty("swt.autoScale.updateOnRuntime", "true");
        Shell shell = new Shell(display);
        shell.setText("Tree with Images in Header");
        shell.setLayout(new FillLayout());

        final Tree tree = new Tree(shell, SWT.MULTI | SWT.FULL_SELECTION);
        tree.setHeaderVisible(true);
        tree.setLinesVisible(true);

        int columnCount = 4;
        Image[] headerImages = new Image[columnCount];

        // Load sample images (replace with your own image paths)
        for (int i = 0; i < columnCount; i++) {
            headerImages[i] = new Image(display, 16, 16); // Placeholder blank image
            GC gc = new GC(headerImages[i]);
            gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
            gc.fillRectangle(0, 0, 16, 16); // Simple colored square as image
            gc.dispose();
        }

        // Create columns with text and images
        for (int i = 0; i < columnCount; i++) {
            TreeColumn column = new TreeColumn(tree, SWT.NONE);
            column.setText("Column " + i);
            column.setImage(headerImages[i]);
        }

        // Populate tree items
        int itemCount = 3;
        for (int i = 0; i < itemCount; i++) {
            TreeItem item1 = new TreeItem(tree, SWT.NONE);
            item1.setText("item " + i);
            for (int c = 1; c < columnCount; c++) {
                item1.setText(c, "item [" + i + "-" + c + "]");
            }
            for (int j = 0; j < itemCount; j++) {
                TreeItem item2 = new TreeItem(item1, SWT.NONE);
                item2.setText("item [" + i + " " + j + "]");
                for (int c = 1; c < columnCount; c++) {
                    item2.setText(c, "item [" + i + " " + j + "-" + c + "]");
                }
                for (int k = 0; k < itemCount; k++) {
                    TreeItem item3 = new TreeItem(item2, SWT.NONE);
                    item3.setText("item [" + i + " " + j + " " + k + "]");
                    for (int c = 1; c < columnCount; c++) {
                        item3.setText(c, "item [" + i + " " + j + " " + k + "-" + c + "]");
                    }
                }
            }
        }

        // Optional: Custom selection gradient (kept from your original snippet)
        tree.addListener(SWT.EraseItem, event -> {
            event.detail &= ~SWT.HOT;
            if ((event.detail & SWT.SELECTED) != 0) {
                GC gc = event.gc;
                Rectangle rect = event.getBounds();
                Color foreground = gc.getForeground();
                Color background = gc.getBackground();
                gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
                gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
                gc.fillGradientRectangle(0, rect.y, 500, rect.height, false);
                gc.setForeground(foreground);
                gc.setBackground(background);
                event.detail &= ~SWT.SELECTED;
            }
        });

        tree.setSortColumn(tree.getColumn(2));
        tree.setSortColumn(tree.getColumn(1));
        tree.setSortDirection(SWT.UP);
        for (int i = 0; i < columnCount; i++) {
            tree.getColumn(i).pack();
        }
        tree.setSelection(tree.getItem(0));

        shell.setSize(500, 200);
        shell.open();

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }

        // Dispose images to avoid memory leaks
        for (Image img : headerImages) {
            img.dispose();
        }

        display.dispose();
    }
}


image

@arunjose696
Copy link
Contributor

@ShahzaibIbrahim can you fix the conflict with master

Since Windows 7, the sort indicator in tree columns is rendered above
the column header text, whereas in Windows XP it was placed next to the
text. The original SWT implementation added extra pixels (SORT_WIDTH) to
the column width to make space for the indicator.
@fedejeanne fedejeanne merged commit 1094ebd into eclipse-platform:master Sep 12, 2025
17 checks passed
@fedejeanne fedejeanne deleted the master-429 branch September 12, 2025 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove legacy SORT_WIDTH spacing logic in SWT.Tree
4 participants