[fxruby-users] FXTable::fitColumnsToContents

Lyle Johnson lyle at lylejohnson.name
Sun May 18 16:45:38 EDT 2008

On May 17, 2008, at 6:54 AM, David Toll wrote:

> I tried to submit the following message to the "fxruby-users"  
> message board (I clicked the link to send it as an email to fxruby-users at rubyforge.org 
> , but the message did not appear).  I conclude I do not know how to  
> submit questions to this message board.

You need to be subscribed to the mailing list before you can send  
questions to it. Are you subscribed? If not, fill out the subscription  
form here:


Note that you need to send messages from the same address that you're  
subscribed under. So if you're subscribed as "tolld at gmail.com" (for  
example), you wouldn't be able to send messages from "tolld at optonline.net 

> In a table column with a header, when I use "fitColumnsToContents",  
> if the header is wider than any of the cells in the column then the  
> header is truncated.  It would appear that the contents of the  
> header are ignored when determining the column width from the column  
> contents.

I took a quick look at the FOX source code and it looks like you're  
right. Only the cells in the body of the table are considered.

> A work-around is to pad the column data with spaces.  However, is  
> there a better way of doing this?

This seems to work; see what you think:

	class FXTable
	  def fitColumnsToContents(col, nc)
	    col.upto(col+nc-1) do |c|
	      cw = getMinColumnWidth(c)
	      hw = columnHeader.font.getTextWidth(columnHeader.getItemText(c))
	      setColumnWidth(c, [cw, hw].max)

Note that this is similar to the original implementation of  
fitColumnsToContents() from FOX; but it also checks the width of the  
column header items to see if they're wider.

> I have another question:
> Many FXRuby objects have a "height" parameter.  However, it seems to  
> be ignored in at least some cases.  For example, if you create an  
> FXText object without "LAYOUT_FILL" or "LAYOUT_FILL_Y" then the text  
> window is something like 3 lines high.  If I add a height parameter,  
> the object height does not change.

True. For those cases you'd need to specify the LAYOUT_FIX_HEIGHT  
layout width to get it to enforce your specified height value.

> A corollary to this is - what are the units for "height" (pixels,  
> lines, inches, ....)? - I have not found this in the API  
> documentation.

Width and height are always in pixels.

> I have a table with column headers.  I changed the header font from  
> the default (Tahoma at about 8 or 9 point) to Tahoma Bold at 10  
> points.  The font changes OK; however, the height of the header is  
> not changed to allow more space for the font - in my case,  
> descenders (such as the bottom of a "y") are chopped off.
> How do I get round this?  My reading of the documentation is that it  
> should automatically increase the size of the header to fit the  
> contents unless you tell it the height is fixed (which is not the  
> case here).

When the table constructs its header, it's passing in the  
LAYOUT_FIX_HEIGHT option. So it's not you that's telling it to use a  
fixed height, but that is in fact what it's doing. To work around  
this, just reset the layout hints for that widget:

	table.columnHeader.layoutHints = 0

> Many thanks for you help.  I suspect many of my problems are because  
> I am a novice at FXRuby.

No, they're good questions and things that aren't obvious from the  
documentation. I always learn something when I have to dig in and  
figure out these problems. ;)

Hope this helps,


"FXRuby: Create Lean and Mean GUIs with Ruby"
Now available from the Pragmatic Bookshelf!

More information about the fxruby-users mailing list