[Java-gnome-developer] Word wrap in a CellRenderText
Brought to you by:
afcowie
From: Andrew C. <an...@op...> - 2005-02-02 12:56:52
|
Hey there, I'm in the process of using a simple single-column ListStore backed TreeView to display a summarized version of some data, and I'm having a little trouble fine tuning the rendering - I need word wrap. As some of you know, I'm working on something which, broadly stated, involves displaying XML data. This particular window is a high level summary, which simplifies navigation around the more specific details of the document in other windows. As such, I've just read in selected XML nodes, and composed a single string - with Pango markup - for display in the TreeView widget. Pango obviously provides for wrapping text in Labels; and likewise TreeView (care of TreeViewColumn and CellRendererText.Attribute.MARKUP) provides for displaying text with pango markup, so text of This is <big>some huge</big> text, and <span size=small>this is small</span> works. The trouble is that there's no markup code (that I can find) for word wrap. I looked up the GNOME manual, and Labels definitely have a wrap property, and java-gnome lets you at it with Label.setLineWrap(true). However, the text cells in a TreeView are not Labels, even though the same pango engine is used to render them. CellRendererText has a method called setAttributes(AttrList attr). That seems to be the way to Pango, but when I look at the org.gnu.pango classes, I can't figure out how to create the Attribute objects which it uses. Within org.gnu.pango there's a Layout class, which has setWrapStyle(WrapMode.WORD), but I can't figure out how to get to Attribute from Layout, or vice versa - for that matter, I can't figure out what generates Layout objects. So obviously I'm way off in left field here. If <span wrap="true"> worked, then this would be easy, but that doesn't work (and, in fact, throws quite the error :)). If I wasn't using a TreeView, then it would just be labels and would be easy - but if I was forced to do that then it would mean trying to manually duplicate the effect of the TreeView widget, and that's going to be near impossible. Help? :) A small screenshot of what I'm fighting against is attached. The lines in italics are all much longer, and the ones that need to be wrapped instead of cut off. AfC Sydney -- Andrew Frederick Cowie Managing Director Sydney: +61 2 9977 6866 New York: +1 646 472 5054 Toronto: +1 416 848 6072 London: +44 207 1019201 OPERATIONAL DYNAMICS Operations Consultants and Infrastructure Engineers http://www.operationaldynamics.com/ |