FunnyName has asked for the wisdom of the Perl Monks concerning the following question:

hello,

i have some problems with TK:Table with dynamic Content and its scrolling-functionality. The Table is created with following params:

$f2->Table( -takefocus => 0, -highlightcolor => $bgColor, -relief => 'groove', -borderwidth => 2, -columns => 3, -fixedrows => 1, -fixedcolumns => 2, -scrollbars => 'se')->pack...

The Content of the Table (rows) is dynamic and therefore changes. If it grows larger, the scrollable Area grows too. (correct) But sometimes i have to remove some rows from the table. (in fact the table is filled from a hash-table each time an update occurs and i have to delete obsolete rows manually, since i use a Version of TK (800.024) in which Table->clear isn't implemented yet.) The removal of the oboslete widgets works fine, but the scrollable Area doesn't resize correctly, so it looks like there are left empty rows at the and of the table, where the deleted rows/widget were.

my $AktRows = $table->totalRows; my $AktCols = $table->totalColumns; my $AnzActivities = keys %AktActivityRec; if( $AnzActivities < ($AktRows-1) ) { for(my $row=($AnzActivities+1); $row < $AktRows; $row++) { for(my $col=0; $col < $AktCols; $col++) { my $widget = $table->get($row, $col); if ($widget) { $table->LostSlave($widget); $widget->destroy(); } } } } $table->update;

How can i force the table to resize the scrollable area?

UPDATE: after some debugging i found out, that it's a problem with the row-count of the table. although the widgets are correctly destroyed the table still contains their rows. but i couldn't find any hint how to remove a complete row from the table. can anyone help?

Replies are listed 'Best First'.
Re: updating size of scrollable Area in TK::Table
by Anonymous Monk on May 11, 2009 at 22:19 UTC
    If Table->clear does it, you can copy Table->clear in your code
    BEGIN { *Tk::Table::clear = \&clear unless defined &Tk::Table::clear; } sub clear { my $self = shift; my $rows = $self->cget(-rows); my $cols = $self->cget(-columns); foreach my $r (1 .. $rows) { foreach my $c (1 .. $cols) { my $old = $self->get( $r, $c ); next unless $old; $self->LostSlave($old); $old->destroy; } } $self->_init; $self->QueueLayout(_SlaveSize); }
      table->clear does use some methods which are not implemented in my version of TK::Table. I do not want to try to copy all that code into my programm, because i saw it using some member variables that are not in my version of TK::table.
Re: updating size of scrollable Area in TK::Table
by zentara (Cardinal) on May 12, 2009 at 10:21 UTC
    Hi, my mind shudders at Tk::Table code. :-) What I will mention, is that scrolled tables often work better when you put a non-scrolled table into a scrolled pane. The scrolled pane somehow allows the table to have it's requested size. You may need a $pane->update, or something similar after a table resize.

    But try it for yourself. Just make a scrolled pane, and pack a non-scrolled table into it, with fill=>'both' and expand=>1 set in the packing options for the table and/or pane. You can adjust the size of the scrolled pane window with a geometry option on the main window.

    Then play around with changing the number of columns/rows and see how it works on your system.

    Of course, I may be missing the point of your problem... :-)


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku