(Better late than never, i guess...) Your code was *almost* right. The problem is that the sizes of the widgets are not known until they are "realized" (made "real" by having their actual X windows created). You hardly ever need to create Adjustments, but can simply use the ones that get created automatically.
$ diff -u monk.pl.orig monk.pl --- monk.pl.orig 2008-01-27 12:04:05.921317488 -0500 +++ monk.pl 2008-01-27 12:03:44.446582144 -0500 @@ -44,15 +44,18 @@ $y > $portrait[1] ? $portrait[1] : $y + 2); } - # all these values are the same as default, except the first. the +se - # values are just for testing. the eventual plan is to adjust the +m - # so the viewport is centered, but even with static values it - # doesn't work. - my $ha = Gtk2::Adjustment->new(50, 0, 1, 0.1, 0.9, 1); - my $va = Gtk2::Adjustment->new(50, 0, 1, 0.1, 0.9, 1); - - $sw->set_hadjustment($ha); - $sw->set_vadjustment($va); + # + # After the widgets are create and know their size, scroll to the + # middle of the image. Notice the halfway point is actually + # (upper-pagesize)/2, not upper/2 --- otherwise you'll attempt to + # scroll out of bounds. + # + $sw->signal_connect_after (realize => sub { + my $va = $_[0]->get_vadjustment; + $va->set_value (($va->upper - $va->page_size) / 2); + my $ha = $_[0]->get_hadjustment; + $ha->set_value (($ha->upper - $ha->page_size) / 2); + }); $mw->set_title("$file ${x}x${y}"); $mw->show_all();

In reply to Re: setting scrollbar position of a Gtk2 ScrolledWindow by Anonymous Monk
in thread setting scrollbar position of a Gtk2 ScrolledWindow by revdiablo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.