[Win32] Table column resizing broken

未关闭
#3,777 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
54/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
java
领域
desktop, frontend

调研方向

Start by tracing how Table.getClientArea() and TableColumn.setWidth() interact with scrollbar sizing on Windows at 175% zoom. The issue provides a reproducer but names no implementation files or tests, so locate the relevant Win32 table code and existing resizing tests first. Done means resizing the window no longer shows a horizontal scrollbar when the column should fit the client area.

由索引模型根据 Issue 内容生成。

描述

HiDPI Windows

Describe the bug
We want a table column to be as wide as the table to avoid a horizontal scrollbar. This is broken with the rounding of getClientArea() for zoom factors like 175% (typical for 4k displays).

To Reproduce

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

public class OneTableColumn {

	public static void main(String[] args) {
		final Display display = new Display();

		final Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());

		final Table table = new Table(shell, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
		table.setHeaderVisible(false);
		final TableColumn column = new TableColumn(table, SWT.LEFT);
		column.setResizable(false);
		table.addListener(SWT.Resize, new Listener() {
			private boolean updating;

			@Override
			public void handleEvent(Event event) {
				updateColumnWidth();
				// Update again after SWT has adjusted the scrollbars.
				display.asyncExec(() -> {
					if (!table.isDisposed()) {
						updateColumnWidth();
					}
				});
			}

			private void updateColumnWidth() {
				if (updating) {
					return;
				}

				updating = true;
				try {
					final int width = table.getClientArea().width;
					if (column.getWidth() != width) {
						column.setWidth(width);
					}
				}
				finally {
					updating = false;
				}
			}
		});

		for (int i = 0; i < 10; i++) {
			new TableItem(table, SWT.NONE).setText("Item " + i);
		}

		shell.setSize(400, 300);
		shell.open();

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

		display.dispose();
	}
}
  • run this snippet on Windows with a zoom factor of 175%
  • resize the window -> the horizontal scrollbar occurs for some window widths
  • even changing column.setWidth(width) to column.setWidth(width - 1) does not prevent the scrollbar from occurring

Expected behavior
The column should be as wide as the client area, but not wider, so no horizontal scrollbar is shown.

Screenshots
Image

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS
  1. Additional OS info (e.g. OS version, Linux Desktop, etc)
    Windows 11 25H2

Workaround (or) Additional context
Workaround: use SWT v4972r4 or earlier

主要语言
Java
星标
202
派生
206
平均合并
1 天 15 小时
30 天内合并 PR
99

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

eclipse-platform/eclipse.platform.swt 的其他 Issue

查看 eclipse-platform/eclipse.platform.swt 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。