Archive for the 'Uncategorized' Category

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:

07
Aug
06

Hello world!

Yeah I’m here. Read the about page to get started ;)




 

June 2012
M T W T F S S
« Dec    
 123
45678910
11121314151617
18192021222324
252627282930  

Follow

Get every new post delivered to your Inbox.