[fxruby-users] a table column that fills horizontally

Joel VanderWerf vjoel at path.berkeley.edu
Sun May 20 19:03:18 EDT 2007


Joel VanderWerf wrote:
> Is there a way to specify that a table column should resize itself to 
> fill available space, so that it is just big enough that there is no 
> unused space in the table, but there is no horizontal scroll bar?
> 
> That might be too special a situation for FXTable in general to handle, 
> but anyway here's a way to do it (tested a little). The +fill+ variable 
> is the column number of the column that should adjust its width.
> 
>          fill_resizer = proc do
>            other_width = table.verticalScrollBar.width +
>              table.rowHeaderWidth +
>              (0...columns.size).inject(0){|sum,c| sum +
>                (c == fill ? 0 : table.getColumnWidth(c))}
>            table.setColumnWidth fill, table.width - other_width - 1
>            false
>          end
>          table.connect(SEL_CONFIGURE, &fill_resizer)
>          table.columnHeader.connect(SEL_CHANGED, &fill_resizer)
> 

This is a slight improvement that is sensitive to whether the scroll bar 
is shown:

         fill_resizer = proc do
           other_width = table.rowHeaderWidth +
             (0...columns.size).inject(0){|sum,c| sum +
               (c == fill ? 0 : table.getColumnWidth(c))}
           vsb = table.verticalScrollBar
           other_width += vsb.width if vsb.shown?
           table.setColumnWidth fill, table.width - other_width - 1
           false
         end
         table.connect(SEL_CONFIGURE, &fill_resizer)
         table.columnHeader.connect(SEL_CHANGED, &fill_resizer)

-- 
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


More information about the fxruby-users mailing list