简体   繁体   English

SWT TableItem:如何删除左边的填充/缩进?

[英]SWT TableItem: How to remove left padding/ indent?

The following piece of code creates an SWT table with two columns and two rows. 下面的代码创建了一个包含两列和两行的SWT表。 On my system, the resulting shell/table looks like this: 在我的系统上,生成的shell /表如下所示:

在此输入图像描述

I can't help but wonder where the extra indent/spacing/padding in front of each cell text comes from. 我不禁想知道每个单元格文本前面的额外缩进/间距/填充来自何处。 I have searched the Web and tried every possible way to remove it, but I cannot find a way. 我搜索过网络并尝试了一切可能的方法将其删除,但我找不到办法。 How do I remove the extra spacing (marked red in the above image)? 如何删除多余的间距(上图中标记为红色)?

System information: 系统信息:

  • Linux Mint 17 Linux Mint 17
  • SWT 4.4 x86_64 SWT 4.4 x86_64

Links: 链接:

This example is originally taken from java2s.com and modified a bit. 这个例子最初取自java2s.com并进行了一些修改。 The screenshot on the original site does not show this spacing/indent. 原始网站上的屏幕截图不显示此间距/缩进。

Code to reproduce this issue: 重现此问题的代码:

public class SwtTableItemIssue {
  public static void main(String[] a) {
    Shell shell = new Shell(Display.getDefault());
    shell.setSize(200, 180);
    shell.setLayout(new FillLayout());

    Table t = new Table(shell, SWT.BORDER);
    t.setHeaderVisible(true);

    TableColumn tc1 = new TableColumn(t, SWT.NONE);
    TableColumn tc2 = new TableColumn(t, SWT.NONE);
    tc1.setText("First Name");
    tc2.setText("Last Name");
    tc1.setWidth(70);
    tc2.setWidth(70);

    new TableItem(t, SWT.NONE).setText(new String[] { "Tim", "Hatton" });
    new TableItem(t, SWT.NONE).setText(new String[] { "Caitlyn", "Warner" });

    shell.open();
    shell.layout();

    Display display = Display.getDefault();

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

    display.dispose();
  }
}

Ok, did a bit of research and turns out it's a GTK3 issue. 好的,做了一些研究,结果发现这是一个GTK3问题。

Since version 4.4, SWT uses GTK3 by default (if available). 从版本4.4开始,SWT默认使用GTK3(如果可用)。 I've tested your code with GTK3 and GTK2 and it works in the latter. 我用GTK3和GTK2测试了你的代码,它适用于后者。

You've now got three options: 你现在有三个选择:

  1. Wait for the SWT team to fix it. 等待SWT团队修复它。
  2. Fall back to an older SWT version. 回归到较旧的SWT版本。
  3. Force SWT (4.4) to use GTK2 instead of GTK3. 强制SWT(4.4)使用GTK2而不是GTK3。

Neither solution is ideal, but I don't see another option. 这两种解决方案都不理想,但我没有看到另一种选择。


You can force SWT to use GTK2 by setting an environment variable: 您可以通过设置环境变量强制SWT使用GTK2:

export SWT_GTK3=0

Make sure to either make this a permanent setting or run it every time before you start your application. 确保将其设置为永久设置或在每次启动应用程序之前运行它。

Here are the release notes of SWT 4.4. 以下是SWT 4.4的发行说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM