Skip to content

Conversation

ShahzaibIbrahim
Copy link
Contributor

The Table.GRID_WIDTH constant specifies the extra width added to a table item when lines between columns are visible (lineVisible = true). This accounts for the space taken by the grid line. Previously, it was defined as a fixed
pixel value, which appeared too small on high-DPI monitors.

This change redefines GRID_WIDTH in points and scales it to pixels based on the current zoom level. At 100% zoom this results in 2px instead of 1px, which is visually negligible but ensures consistency by keeping all constants defined in points and scaled according to zoom level.

How to Test

  • Run the following snippet on a Primary monitor with 250% zoom
  • You will notice extra pixel in the width compared to previous state.

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

public class LinesVisibleTableExample {

    public static void main (String [] args) {
        System.setProperty("swt.autoScale", "quarter");
        System.setProperty("swt.autoScale.updateOnRuntime", "true");
        
        Display display = new Display ();
        Shell shell = new Shell (display);
        shell.setText("SWT Table Example");
        shell.setLayout(new FillLayout());

        // Create table
        final Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
        table.setHeaderVisible(true);
        table.setLinesVisible(true);

        // Create columns
        String[] titles = { "Level 0", "Level 1", "Level 2", "Level 3" };
        for (String title : titles) {
            TableColumn column = new TableColumn(table, SWT.NONE);
            column.setText(title);
            column.setWidth(100);
        }

        // Fill table with hierarchical-like data
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                for (int k = 0; k < 4; k++) {
                    for (int l = 0; l < 4; l++) {
                        TableItem item = new TableItem(table, SWT.NONE);
                        item.setText(new String[] {
                            "TableItem (0) -" + i,
                            "TableItem (1) -" + j,
                            "TableItem (2) -" + k,
                            "TableItem (3) -" + l
                        });
                    }
                }
            }
        }

        shell.setSize(450, 250);
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) display.sleep();
        }
        display.dispose();
    }
}

Copy link
Contributor

github-actions bot commented Aug 27, 2025

Test Results

   546 files  ±0     546 suites  ±0   33m 10s ⏱️ + 2m 27s
 4 426 tests ±0   4 409 ✅ ±0   17 💤 ±0  0 ❌ ±0 
16 750 runs  ±0  16 623 ✅ ±0  127 💤 ±0  0 ❌ ±0 

Results for commit a3526b1. ± Comparison against base commit 9bf4caf.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@akoch-yatta akoch-yatta left a comment

Choose a reason for hiding this comment

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

Changes are very similar to #2443. Changes look sound and I didn't find any problems when testing the changes.

@akoch-yatta akoch-yatta force-pushed the master-404-TABLE-GRID_WIDTH branch from 85f0873 to 8b3c28e Compare September 4, 2025 07:20
The Table.GRID_WIDTH constant specifies the extra width added to a table
item
when lines between columns are visible (`lineVisible = true`). This
accounts
for the space taken by the grid line. Previously, it was defined as a
fixed
pixel value, which appeared too small on high-DPI monitors.

This change redefines GRID_WIDTH in points and scales it to pixels based
on
the current zoom level. At 100% zoom this results in 2px instead of 1px,
which is visually negligible but ensures consistency by keeping all
constants
defined in points and scaled according to zoom level.
@akoch-yatta akoch-yatta force-pushed the master-404-TABLE-GRID_WIDTH branch from 8b3c28e to a3526b1 Compare September 4, 2025 07:23
@akoch-yatta akoch-yatta merged commit 1ae0e18 into eclipse-platform:master Sep 4, 2025
17 checks passed
@akoch-yatta akoch-yatta deleted the master-404-TABLE-GRID_WIDTH branch September 4, 2025 07:45
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.

Scale Table.GRID_WIDTH by zoom level instead of using fixed pixels
2 participants