Hello Haris,
On Sun, Dec 27, 2009 at 8:54 PM, Haris Bogdanovic <lists at
ruby-forum.com>wrote:
> Haris Bogdanovic 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
>
^^^^^^^
This specific line is what is causing the problems.
end>
> end
>
> class HelloWorld < Wx::App
> def on_init
> f = MainFrame.new
> f.show
> end
> 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
--
Mario Steele
http://www.trilake.net
http://www.ruby-im.net
http://rubyforge.org/projects/wxruby/
http://rubyforge.org/projects/wxride/
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/wxruby-users/attachments/20091228/a9507f1c/attachment.html>