Skip to content

[Win32] Table's horizontal ScrollBar doesn't fire SelectionEvents when column width is changed. #2878

@wtlnw

Description

@wtlnw

Describe the bug
When a Table's column width is changed (e.g. via dragging of column handle in UI or through ColumnItem.setWidth() API), the table's horizontal ScrollBar doesn't fire any SelectionEvents despite the fact that its selection value actually changes.

To Reproduce
Run the below snipplet, scroll all the way to the right first (this is very imporant!) and then make Column 1 smaller. While doing so, the ScrollBar's thumb gets bigger until it disappears - this is perfectly fine. However, no SelectionEvents are fired despite the fact that the selection value changes.

	public static void main(final String[] args) {
		final Display display = new Display();
		final Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());

		// initialize to a specific width in order to set
		// the column width so that horizontal scroll bar
		// is definitely there.
		shell.setSize(640, 480);

		final Table table = new Table(shell, SWT.H_SCROLL);
		table.setHeaderVisible(true);

		final TableColumn column1 = new TableColumn(table, SWT.NONE);
		column1.setText("Column 1");
		column1.setWidth(480);

		final TableColumn column2 = new TableColumn(table, SWT.NONE);
		column2.setText("Column 2");
		column2.setWidth(480);

		table.getHorizontalBar().addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
			System.out.println("Selection changed: " + ((ScrollBar) e.widget).getSelection());
		}));
		
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}

Expected behavior
We expect the ScrollBar to fire a SelectionEvent because its selection value changes due to the fact that its value range (being maximum - minimum - thumb) changes. The value range changes because the ScrollBar's maximum value changes according to the total sum of column widths.

Note that it's correct that it does not fire events when you scroll all the way to the left or stay in the middle of the scroll bar because the selection value does not change when you resize the column's width in that case.

Environment:

    • All OS
    • Windows
    • Linux
    • macOS

Tested on Windows 10 and 11, both have the same problem.

Version since
SWT v3.131.0, win32.x86_64

Workaround (or) Additional context
The only way to work around this problem is to force the ScrollBar to fire a SelectionEvent manually when the column width is changed (e.g. ScrollBar.notifyListeners(SWT.Selection, new Event())), but that's only possible if you are changing a column's width programmatically and you know that. Other than that, there is currently no way to detect it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    WindowsHappens on Windows OS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions