# Problems with ToolBar Sintaxis

**URL:** <https://www.ruby-forum.com/t/problems-with-toolbar-sintaxis/149636>\
**Category:** wxRuby\
**Created:** [September 27, 2008, 2:03am UTC](https://www.ruby-forum.com/t/problems-with-toolbar-sintaxis/149636 "2008-09-27T02:03:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f17d59/32.png) [@ramo](https://www.ruby-forum.com/u/ramo)\
**Post date:** [September 27, 2008, 2:03am UTC](https://www.ruby-forum.com/t/problems-with-toolbar-sintaxis/149636/1 "2008-09-27T02:03:34Z")

</div>

First of all, it’s my first week learnig ruby and so is for wxruby,also  
this is my first time working with a GUI so please, please, be patient.

I’m having problems with the code for a toolbar, i want to add an item,  
but a don’t know how. this is my code for now:

@toolBarPrincipal=ToolBar.new(@panel)  
@toolBarPrincipal.add\_tool(-1, ‘&Bonzai’, Bitmap.new(“/home/…  
icon.ico”))

I’ve already red the [http://wxruby.rubyforge.org/doc/toolbar.html](http://wxruby.rubyforge.org/doc/toolbar.html) page  
(mi code is basically what comes there.

I want to put it into a panel, named panel. At this point, a litle dot  
is drawn on the top-left corner (under a menu bar) but no icon.

I’d appreciate if you help me. A correction, some code examples or some  
links would be perfect.

Thanks!!

Sorry if i’m making a thread that already exists (i searched first)

---

<div class="post-metadata">

**Author:** ![ramo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f17d59/32.png) [@ramo](https://www.ruby-forum.com/u/ramo)\
**Post date:** [September 27, 2008, 1:08pm UTC](https://www.ruby-forum.com/t/problems-with-toolbar-sintaxis/149636/2 "2008-09-27T13:08:55Z")

</div>

What’s going on, is that the Toolbar is not resizing, so you need to  
either  
resize the toolbar yourself, or you need to use Wx::BoxSizer.  
Personally,  
Wx::BoxSizer is easier to do.

Simply do the following:

box = Wx::BoxSizer.new(Wx::HORIZONTAL)  
box.add(@toolBarPrincipal,1,Wx::ALL)  
@panel.set\_sizer(box)

This will allow the Toolbar to expand to take up as much space as  
possible,  
least you put in another control with the Toolbar itself (Not the  
Toolbar  
Item)

Hope this helps.

---

<div class="post-metadata">

**Author:** ![ramo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f17d59/32.png) [@ramo](https://www.ruby-forum.com/u/ramo)\
**Post date:** [September 27, 2008, 1:11pm UTC](https://www.ruby-forum.com/t/problems-with-toolbar-sintaxis/149636/3 "2008-09-27T13:11:16Z")

</div>

Hi

Omar H. wrote:

> I want to put it into a panel, named panel. At this point, a litle dot  
> is drawn on the top-left corner (under a menu bar) but no icon.

Maybe you need to call ToolBar#realize after you’ve added all your  
items?

Or if you are placing the ToolBar within a panel, maybe you need to use  
a Sizer to allocate space for the ToolBar?

If the ToolBar is intended as the main ToolBar for a frame, it can be  
better to call Frame#create\_tool\_bar or Frame#set\_tool\_bar. This will  
deal with the sizing, and also ensure that the ToolBar has a native  
style - on OS X, a native toolbar can only be on the top.

> I’d appreciate if you help me. A correction, some code examples or some  
> links would be perfect.  
> You might take a look at the wxToolBar.rb sample in samples/bigdemo/;  
> you should find the sampes installed in your gems directory.

If you want further help, please post a short, complete, runnable sample  
with your toolbar code.

hth  
alex

---

<div class="post-metadata">

**Author:** ![ramo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f17d59/32.png) [@ramo](https://www.ruby-forum.com/u/ramo)\
**Post date:** [September 29, 2008, 9:49pm UTC](https://www.ruby-forum.com/t/problems-with-toolbar-sintaxis/149636/4 "2008-09-29T21:49:09Z")

</div>

Thank you

they both (Mario S.'s and Alex F.'s) worked.

It is a main toolbar, is like the file\_new, file\_open toolbars of most  
programs so I ended up using the Frame#create\_tool\_bar method and I  
checked the sample:

wxToolBar.rb in samples/bigdemo/ in the gems directory

see ya.
