Archive for December, 2009

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:




 

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

Follow

Get every new post delivered to your Inbox.