22
Dec
09

Tighter rows in TreeView with SWT + GTK

As mentioned here and here and here, the GTK version of SWT wastes much space in tables and trees. Even with the GTK theming, rows in trees have still too much space between them:

I spent some time with GDB to find out where the additional padding above and below the text of each item comes from. In the end I found out, that text cell renderers in GTK (gtk/gtkcellrenderertext.c) have a default y-padding of 2 pixels set:
GTK_CELL_RENDERER (celltext)->ypad = 2

While you can’t do much to fix it in Eclipse right now, here’s the hack to make it work for your own SWT programs:

val t: swt.widgets.Tree = //

import swt.internal.gtk.OS
val rendererMethod = t.getClass.getDeclaredMethod("getTextRenderer", java.lang.Long.TYPE)
rendererMethod.setAccessible(true)
val h = OS.gtk_tree_view_get_column (t.handle, 0)
val r = rendererMethod.invoke(t,java.lang.Long.valueOf(h)).asInstanceOf[java.lang.Long].longValue
OS.g_object_set (r, OS.ypad, 0, 0)

With this set, the tree from above looks much more compact:

About these ads

3 Responses to “Tighter rows in TreeView with SWT + GTK”


  1. 1 mbana
    January 22, 2010 at 13:09

    is it possible to change eclipse _only_ to use less spacein trees. compared to other IDEs such as IDEA, it seems to be wasting a lot of space.

  2. 2 Johannes
    January 27, 2010 at 17:56

    No, unfortunaltely it isn’t possible to change that from the outside. You would need a patch to SWT GTK to make this setting controlable.

    • 3 John
      February 27, 2014 at 1:30

      I was able to download the swt gtk source and modified the Table.java and Tree.java source.
      In the createRenders method:

      After the following code …
      long /*int*/ textRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_text_get_type (), 0) : OS.gtk_cell_renderer_text_new ();
      if (textRenderer == 0) error (SWT.ERROR_NO_HANDLES);

      I added …
      if (OS.IsAIX)
      {
      int pad = 0;
      OS.g_object_set (textRenderer, OS.ypad, pad, 0);
      }

      while this issue doesn’t seem to be a problem for linux anymore, it still is an issue with aix.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


December 2009
M T W T F S S
« Mar    
 123456
78910111213
14151617181920
21222324252627
28293031  

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: