7

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!

Campa
  • 4,267
  • 3
  • 37
  • 42
jastram
  • 733
  • 7
  • 19
  • Actually, I might have found an explanation for this behavior, and maybe even a fix (I still have to try this out): https://bugs.eclipse.org/bugs/show_bug.cgi?id=148039 – jastram Nov 02 '10 at 21:42
  • Thanks all for the answers. I ended up using http://sourceforge.net/projects/agilegrid/ , which also draws the table natively, like KTable. It's a pleasure to work with, certainly compared to SWT. – jastram Dec 14 '10 at 13:20

3 Answers3

4

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.

thehiatus
  • 1,575
  • 13
  • 23
  • This looks really interesting. If I hadn't refactored with AgileGrid yet, I would give Ktable a try. – jastram Dec 14 '10 at 13:21
2

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.

the.duckman
  • 6,376
  • 3
  • 23
  • 21
1

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

fisherja
  • 309
  • 2
  • 7
  • Are you sure that Nebula addresses this issue? I believe that I did check it out and rejected it. I am not sure weather I rejected it because it was in ALPHA, or because it also had the row height limitations. But I *think* it was because of row height issues as well. – jastram Dec 14 '10 at 13:18
  • To get the variable heights is not completely out of the box but it is very straight forward. Each row in the Grid has its own independent height attribute. So where as on paint/measure in a normal table widget you could adjust the height but all tableitems are now that max height in Grid you can adjust each GridItem.setHeight(). In my case I am using the grid table viewer and having my label provider update method calculate the appropriate height for each row. It is Beta but has been very stable for us for the last 2+ years or so. – fisherja Dec 21 '10 at 20:18