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.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 2, 2025

Test Results

   546 files  ±0     546 suites  ±0   33m 19s ⏱️ - 3m 53s
 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 f9ea6d7. ± Comparison against base commit c6a29a9.

♻️ This comment has been updated with latest results.

Copy link
Member

@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. Changes look good to me.
As I am on macOS I cannot test these changes.

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.
@arunjose696
Copy link
Contributor

Have tested the changes with a table with image the changes look good

Copy link
Member

@fedejeanne fedejeanne left a comment

Choose a reason for hiding this comment

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

Same as with #2476 (see #2476 (comment)), the image in the column gets lost when the column is selected. I know this PR didn't introduce this behavior (bug?) but I'd like to point it out anyway.

Since I can see that you didn't remove/ignore any instance Image in this PR, I am approving it and merging it, but please keep in mind my comment about preserving the image in the other PR and, if necessary, create a follow-up issue for Table too.

By the way, I tested your changes with a slight adaptation of Arun's snippet:

TableColumnImageHeaderExample (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 TableColumnImageHeaderExample {

    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("Table with Images in Header");
        shell.setLayout(new FillLayout());

        final Table table = new Table(shell, SWT.MULTI | SWT.FULL_SELECTION);
        table.setHeaderVisible(true);
        table.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]);
            System.out.println("image[" + i + "]=" + 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++) {
            TableColumn column = new TableColumn(table, SWT.NONE);
            column.setText("Column " + i);
            column.setImage(headerImages[i]);
        }

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

        // Optional: Custom selection gradient (kept from your original snippet)
        table.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;
            }
        });

        table.setSortColumn(table.getColumn(2));
        table.setSortColumn(table.getColumn(1));
        table.setSortDirection(SWT.UP);
        for (int i = 0; i < columnCount; i++) {
            table.getColumn(i).pack();
        }
        table.setSelection(table.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();
    }
}

@fedejeanne fedejeanne merged commit 9164303 into eclipse-platform:master Sep 12, 2025
17 checks passed
@fedejeanne fedejeanne deleted the master-430 branch September 12, 2025 07:40
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.Table

4 participants