Wxscrolledwindow

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

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

Hello Haris,

On Sun, Dec 27, 2009 at 8:54 PM, Haris B.
[email protected]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),
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

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