具有可变行高的 SWT 表:适用于 Linux,但不适用于 Mac/Windows

发布于 2024-09-30 08:10:36 字数 1418 浏览 0 评论 0原文

问题:我需要一个具有可变行高的 SWT 表(JFace TableViewer)。事实上,我在我的开发机器上解决了这个问题(运行 Ubuntu 10.10)。不幸的是,这在 Windows 和 Mac 上都不起作用。

最初,我以为我没有正确使用这些库。但现在我担心我想做的事情在 Windows 上根本不可能实现。我希望这里有人能说服我。

重现:我没有在这里提供我的代码,而是构建了一个最小的程序来重现问题。我从以下代码片段开始:

http://git.eclipse.org/c/platform/eclipse.platform.ui.git/tree/examples/org .eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/Snippet049StyledCellLabelProvider.java

我修改了 update() 方法,为目录生成两行文本,为文件生成一行文本(模拟行高可变的环境):

...
if (file.isDirectory()) {
    cell.setText(styledString.toString() + "\n"
        + styledString.toString());
    cell.setImage(IMAGE1);
} else {
    cell.setImage(IMAGE2);
}
...

这在 Linux 上按预期工作,但在 Windows 上所有行都具有相同的高度。具体来说,只有一根线可见。

接下来,我试图通过使measure() 更加智能来帮助SWT。所以我重写了measure(),如下所示:

protected void measure(Event event, Object element) {
    if (((File) element).isDirectory()) {
        event.height = 32;
    } else {
        event.height = 16;
    }
    super.measure(event, element);
}

结果:所有行的高度均为32。同样,这在Linux 上按预期工作。

我担心的是,在 Windows 上,所有行都必须具有相同的高度。这对我来说将是一场精彩的表演。任何人都可以证实这一点,或者更好的是,提供解决方法吗?

谢谢!

Problem: I need an SWT Table (JFace TableViewer) with variable row height. In fact, I solved this on my development machine (running Ubuntu 10.10). Unfortunately, this doesn't work on Windows nor on Mac.

Initially, I thought I didn't use the libraries correctly. But by now I fear that what I want to do is simply not possible on Windows. I hope someone here convinces me otherwise.

To reproduce: rather than providing my code here, I built a minimal program to reproduce the problem. I started with the following Snipplet:

http://git.eclipse.org/c/platform/eclipse.platform.ui.git/tree/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/Snippet049StyledCellLabelProvider.java

I modified the update() method to produce two lines of text for directories and one line for files (to simulate an environment with variable row heights):

...
if (file.isDirectory()) {
    cell.setText(styledString.toString() + "\n"
        + styledString.toString());
    cell.setImage(IMAGE1);
} else {
    cell.setImage(IMAGE2);
}
...

This works as intended on Linux, but on Windows all rows have the same height. Specifically, only one line is visible.

Next, I was trying to help SWT by making measure() more intelligent. So I rewrote measure() like this:

protected void measure(Event event, Object element) {
    if (((File) element).isDirectory()) {
        event.height = 32;
    } else {
        event.height = 16;
    }
    super.measure(event, element);
}

The result: All rows have the height 32. Again, this works as intended on Linux.

My fear is, that on Windows simply all rows must be the same height. This would be a showstopper for me. Can anybody confirm this, or even better, provide a workaround?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

聚集的泪 2024-10-07 08:10:36

我也遇到了这个问题——需要一个可以支持不同高度的单元格的 SWT 表格小部件。正如 the.duckman 所说,Win32 表行无法执行此操作。我们最终使用了 KTable 小部件。它不使用本机操作系统表。

http://sourceforge.net/projects/ktable/

它对我们来说效果很好,但它有一些怪癖。幸运的是,源代码很容易修改以满足您的需求。

I ran into this problem as well -- needing an SWT table widget that could support cells of varying heights. As the.duckman says, Win32 table rows cannot do this. We ended up using the KTable widget. It doesn't use the native OS tables.

http://sourceforge.net/projects/ktable/

It worked okay for us, but it's got some quirks. Luckily the source code is fairly easy to modify to suit your needs.

じее 2024-10-07 08:10:36

我可以确认在 Win32 上表行只能具有相同的高度。例如,请参阅此错误报告。 bug 148039 的解决方法使 setItemHeight() 可以访问,但这并没有改变此限制。

I can confirm that on Win32 table rows can only have same height. See for example this bug report. The workaround from bug 148039 makes setItemHeight() accessible, but that doesn't change this restriction.

沙沙粒小 2024-10-07 08:10:36

我们使用 Nebula Grid 小部件。
http://www.eclipse.org/nebula/widgets/grid/grid。 php

非常灵活。在我们的例子中,我们使用它来获得更多与 treeViewer 小部件相结合的 html 样式表功能。

截屏
替代文本

We use the Nebula Grid widget.
http://www.eclipse.org/nebula/widgets/grid/grid.php

It is exceptionally flexible. In our case we use it to get more of html style table functionality combined with a treeViewer widget.

Screenshot
alt text

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文