# Set scrollbar postion

**URL:** <https://www.ruby-forum.com/t/set-scrollbar-postion/128807>\
**Category:** Ruby-Gnome 2\
**Created:** [February 11, 2008, 6:49pm UTC](https://www.ruby-forum.com/t/set-scrollbar-postion/128807 "2008-02-11T18:49:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cbourne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a88e57/32.png) [@cbourne](https://www.ruby-forum.com/u/cbourne)\
**Post date:** [February 11, 2008, 6:49pm UTC](https://www.ruby-forum.com/t/set-scrollbar-postion/128807/1 "2008-02-11T18:49:34Z")

</div>

Hi,

Does any one know how to set the scrollbar position. I am able to get  
the scrollbar and all it’s ancestors but I am not sure how to  
programmatically change the position of the scrollbar. In my case I  
would like it to be right at the bottom.

I found Gtk::Range has a signal called ‘move-slider’ but from what I  
understand signals are for listening to changes in objects and make the  
actual changes however I may be wrong.

Anyone know how I could do this.

Thanks,

Carl

[http://www.gaihosa.com](http://www.gaihosa.com)

---

<div class="post-metadata">

**Author:** ![cbourne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a88e57/32.png) [@cbourne](https://www.ruby-forum.com/u/cbourne)\
**Post date:** [February 11, 2008, 7:48pm UTC](https://www.ruby-forum.com/t/set-scrollbar-postion/128807/2 "2008-02-11T19:48:27Z")

</div>

On Mon, Feb 11, 2008 at 06:49:34PM +0100, Carl B. wrote:

> Hi,
> 
> Does any one know how to set the scrollbar position. I am able to get  
> the scrollbar and all it’s ancestors but I am not sure how to  
> programmatically change the position of the scrollbar. In my case I  
> would like it to be right at the bottom.

You should be able to use Gtk::Range.value= or  
Gtk::Range.adjustment.value to set it. You can see the upper and lower  
limits by using Gtk::Range.adjustment.upper or .lower.

HTH,

-pete

---

<div class="post-metadata">

**Author:** ![cbourne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a88e57/32.png) [@cbourne](https://www.ruby-forum.com/u/cbourne)\
**Post date:** [February 11, 2008, 10:10pm UTC](https://www.ruby-forum.com/t/set-scrollbar-postion/128807/3 "2008-02-11T22:10:55Z")

</div>

Peter J. wrote:

> On Mon, Feb 11, 2008 at 06:49:34PM +0100, Carl B. wrote:
> 
> > Hi,
> > 
> > Does any one know how to set the scrollbar position. I am able to get  
> > the scrollbar and all it’s ancestors but I am not sure how to  
> > programmatically change the position of the scrollbar. In my case I  
> > would like it to be right at the bottom.
> 
> You should be able to use Gtk::Range.value= or  
> Gtk::Range.adjustment.value to set it. You can see the upper and lower  
> limits by using Gtk::Range.adjustment.upper or .lower.
> 
> HTH,
> 
> -pete

Thanks for the answer but that is what I tried. It only moved the  
scrollbar part way as so.  
Before setting the value of Gtk::Range.  
Gtk::Adjustment.upper returned 255.

After calling this line of code.  
Gtk::Range.value = Gtk::Adjustment.upper  
Gtk::Adjustment.upper returned 15.

I just found the answer and it was pretty clear when I gave it some  
thought. To move the scrollbar all the way to the other side(or bottom)  
use Gtk::ScrolledWindow.hscrollbar/vscrollbar.adjustment.inverted =  
true. Since the scrollbar starts at 0 and this setting will make the  
oppostie end of the scrollbar 0, it will move the slider to the  
end/bottom. I also noticed that anytime text is appended the scrollbar  
will stay at the end/bottom.

Thanks for the help,

Carl

[http://www.gaihosa.com](http://www.gaihosa.com)

---

<div class="post-metadata">

**Author:** ![cbourne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a88e57/32.png) [@cbourne](https://www.ruby-forum.com/u/cbourne)\
**Post date:** [February 12, 2008, 4:12pm UTC](https://www.ruby-forum.com/t/set-scrollbar-postion/128807/4 "2008-02-12T16:12:00Z")

</div>

> [http://www.gaihosa.com](http://www.gaihosa.com)

a side note on:

[http://www.gaihosa.com/ruby/Byte%20Array%20to%20String.html](http://www.gaihosa.com/ruby/Byte%20Array%20to%20String.html)

where you say:

Ruby being as powerful as it is simple to code in still isn’t 100  
percent perfect. One such requirement to make life easier would be a  
method to convert a byte array into a string such as Java’s String str  
= new String(byte[])

and then you go a long way to come up with:

def byte\_array\_to\_string(byte\_array)  
string = ‘’  
byte\_array.each do |byte|  
string.concat(byte.chr)  
end  
return string  
end

what is curious is that you are aware of #unpack. there is an opposite  
method, #pack, which does exactly what you think is lacking (but is  
not):

“byte\_array\_to\_string(input)” yields the same results as  
“input.pack(‘U\*’)”

now for some self advert: you could have found the information easily  
in pleac, it’s in this chapter:  
[http://pleac.sourceforge.net/pleac\_ruby/strings.html#AEN26](http://pleac.sourceforge.net/pleac_ruby/strings.html#AEN26)

btw, avoid “new String(byte[])” in java, as it depends on platform’s  
default encoding. always use the two arguments form and tell java that  
the byte array is UTF-8, ISO-8859-1, or whatever it’s encoded in, it  
will save you from being severely bitten someday you decide to install  
your new server with other defaults.

–  
Guillaume C. - [Guillaume Cottenceau](http://zarb.org/~gc/)
