具有可变行高的SWT表:在Linux上运行,但不在Mac / Windows上运行 [英] SWT Table with variable row height: Working on Linux, but not Mac/Windows

查看:141
本文介绍了具有可变行高的SWT表:在Linux上运行,但不在Mac / Windows上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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.

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

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

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

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);
}
...

这适用于Linux,但在Windows上,所有行都具有相同的高度。具体来说,只有一行是可见的。

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

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

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);
}

结果:所有行的高度都是32.再次,这在Linux上可以正常工作。

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

我担心,在Windows上,所有行的高度必须相同。这对我来说是一个噱头。任何人都可以确认这个,甚至更好,提供一个解决方法吗?

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?

谢谢!

推荐答案

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

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.

这篇关于具有可变行高的SWT表:在Linux上运行,但不在Mac / Windows上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆