You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Eclipse RCP本地构建exe与IDE运行时Nattable下拉框缩放异常问题

解决Eclipse RCP构建后Nattable Combobox高DPI缩放下拉方向异常问题
  • 检查并添加高DPI适配VM参数
    在RCP应用的启动配置文件(如your-app-name.ini)中添加以下参数,确保应用正确识别系统缩放比例:

    -Dswt.autoScale=true
    -Dswt.autoScale.method=nearest
    -Dsun.java2d.dpiaware=true
    

    同时确认IDE运行时的VM参数和构建后的启动参数一致,避免环境差异。

  • 验证Nattable版本兼容性
    检查当前使用的Nattable版本是否适配Java 17和Eclipse RCP 4.26。建议升级到Nattable 2.0.x及以上版本,该系列对高DPI场景和新Java版本有更好的支持。

  • 自定义Combobox下拉位置计算逻辑
    重写ComboBoxCellEditor的下拉展开逻辑,手动根据缩放比例和屏幕边界判断展开方向:

    import org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor;
    import org.eclipse.swt.graphics.Rectangle;
    import org.eclipse.swt.widgets.Display;
    
    public class DpiAwareComboBoxCellEditor extends ComboBoxCellEditor {
    
        @Override
        protected void openDropdown() {
            Display display = getControl().getDisplay();
            // 获取系统缩放比例(96DPI为100%缩放)
            double scaleFactor = display.getDPI().x / 96.0;
            Rectangle controlBounds = getControl().getBounds();
            Rectangle monitorBounds = display.getPrimaryMonitor().getBounds();
            Point dropdownSize = getDropdownSize();
    
            // 计算向下展开是否超出屏幕范围(缩放后)
            boolean canExpandDown = (controlBounds.y + controlBounds.height + dropdownSize.y) 
                <= (monitorBounds.height * scaleFactor);
    
            if (!canExpandDown) {
                // 强制向上展开
                getDropdown().setLocation(controlBounds.x, 
                    (int)(controlBounds.y - dropdownSize.y / scaleFactor));
            } else {
                super.openDropdown();
            }
        }
    }
    

    在Nattable配置中替换原有ComboBoxCellEditor为自定义实现。

  • 检查构建依赖与产品配置

    1. 确保RCP产品配置(.product文件)中包含所有必要的Nattable和SWT依赖,特别是org.eclipse.nebula.widgets.nattable.core、org.eclipse.swt.win32.win32.x86_64(对应系统架构)。
    2. 在产品配置的“Launching”标签页中,将IDE运行时的VM参数同步到构建后的启动参数中。
  • 固化高DPI兼容设置(通过Manifest)
    为构建的exe添加Windows高DPI兼容Manifest,避免用户手动设置兼容性:
    创建app.manifest文件,内容如下:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
        <application xmlns="urn:schemas-microsoft-com:asm.v3">
            <windowsSettings>
                <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
                <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
            </windowsSettings>
        </application>
    </assembly>
    

    在RCP构建配置中指定该Manifest文件,确保打包时嵌入到exe中。

内容的提问来源于stack exchange,提问作者Rezan Hannan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 03:10:12