# Wxscrolledwindow

**URL:** <https://www.ruby-forum.com/t/wxscrolledwindow/180725>\
**Category:** wxRuby\
**Created:** [December 27, 2009, 11:30pm UTC](https://www.ruby-forum.com/t/wxscrolledwindow/180725 "2009-12-27T23:30:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![haris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ccd318/32.png) [@haris](https://www.ruby-forum.com/u/haris)\
**Post date:** [December 27, 2009, 11:30pm UTC](https://www.ruby-forum.com/t/wxscrolledwindow/180725/1 "2009-12-27T23:30:18Z")

</div>

Hi.

Could someone give me a simple example on how to use ScrolledWindow  
class ?  
I want to be able to draw on a panel that’s many times higher than  
window  
holding it (which has vertical scroll bars).

Thanks  
Haris

---

<div class="post-metadata">

**Author:** ![haris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ccd318/32.png) [@haris](https://www.ruby-forum.com/u/haris)\
**Post date:** [December 28, 2009, 2:54am UTC](https://www.ruby-forum.com/t/wxscrolledwindow/180725/2 "2009-12-28T02:54:53Z")

</div>

Haris B. wrote:

> Hi.
> 
> Could someone give me a simple example on how to use ScrolledWindow  
> class ?  
> I want to be able to draw on a panel that’s many times higher than  
> window  
> holding it (which has vertical scroll bars).
> 
> Thanks  
> Haris

Why is this piece of code crashing:

require “wx”

class MainFrame \< Wx::ScrolledWindow  
def initialize  
super nil  
end

end

class HelloWorld \< Wx::App  
def on\_init  
f = MainFrame.new  
f.show  
end  
end

HelloWorld.new.main\_loop

Thanks  
Haris

---

<div class="post-metadata">

**Author:** ![haris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ccd318/32.png) [@haris](https://www.ruby-forum.com/u/haris)\
**Post date:** [December 28, 2009, 12:29pm UTC](https://www.ruby-forum.com/t/wxscrolledwindow/180725/3 "2009-12-28T12:29:59Z")

</div>

Hello Haris,

On Sun, Dec 27, 2009 at 8:54 PM, Haris B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> > Haris
> 
> Why is this piece of code crashing:
> 
> require “wx”
> 
> class MainFrame \< Wx::ScrolledWindow  
> def initialize  
> super nil

```
  ^^^^^^^

```

This specific line is what is causing the problems.

end

> HelloWorld.new.main\_loop  
> You can’t create a ScrolledWindow as a Top Level Window, in Generic  
> Terms.  
> In specific terms relating to wxWidgets, only a Frame (Or TopLevelFrame  
> or  
> anything sub-classed from Frame or TopLevelFrame), or a Dialog (Same as  
> with  
> Frame) can be created without a parent. If you look at  
> ScrolledWindow’s  
> Documentation here  
> ([http://wxruby.rubyforge.org/doc/scrolledwindow.html](http://wxruby.rubyforge.org/doc/scrolledwindow.html)),  
> near the top, there’s a Derived from (Or specifically Subclassed from),  
> you’ll see a breakdown of the classes that ScrolledWindow inherits from,  
> Wx::Object being the top of the Inheritance, followed by EvtHandler,  
> Window,  
> and Panel. Frame is not mentioned anywhere in there. So in order to  
> create  
> a ScrolledWindow, you need to have it as a child of a Frame. A simple  
> example of this being:

class MyFrame \< Wx::Frame  
def initialize  
super nil # This is perfectly fine, cause Frame doesn’t require a  
parent.  
@scrolled = Wx::ScrolledWindow.new(self) # This now creates a  
ScrolledWindow as a child, and only child of our frame.  
end  
end

class HelloWorld \< Wx::App  
def on\_init  
f = MyFrame.new  
f.show  
end  
end

HelloWorld.new.main\_loop

Keep this in mind whenever you go to create a widget in wxRuby without a  
parent, you ensure that it is Derived or Subclassed from a Frame.

As to your previous post, take a look at the samples directory in your  
wxRuby gem directory, for an example of how to use Wx::ScrolledWindow.

hth,

Mario

---

<div class="post-metadata">

**Author:** ![haris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ccd318/32.png) [@haris](https://www.ruby-forum.com/u/haris)\
**Post date:** [December 28, 2009, 5:21pm UTC](https://www.ruby-forum.com/t/wxscrolledwindow/180725/4 "2009-12-28T17:21:40Z")

</div>

Thanks Mario.

I figured out myself in the mean time that  
scrolled window has to have parent window  
but thanks anyway.

I looked again and found ScrolledWindow sample in bigdemo folder.

Thanks  
Haris
