# Titled border

**URL:** <https://www.ruby-forum.com/t/titled-border/165201>\
**Category:** wxRuby\
**Created:** [April 10, 2009, 4:09am UTC](https://www.ruby-forum.com/t/titled-border/165201 "2009-04-10T04:09:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pierre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d07c76/32.png) [@pierre](https://www.ruby-forum.com/u/pierre)\
**Post date:** [April 10, 2009, 4:09am UTC](https://www.ruby-forum.com/t/titled-border/165201/1 "2009-04-10T04:09:41Z")

</div>

Hi folks,

I have a few ListBox controls in my small app, and I wanted to put a  
kind of title above each of them.  
The easiest and somehow best looking solution I had thought of, was a  
kind of border around the ListBox which would have some text at it’s  
top. ( for instance like:  
[http://www.cloudgarden1.com/swing\_tutorial/titled\_border.png](http://www.cloudgarden1.com/swing_tutorial/titled_border.png) the left  
circle ).

Is there anything like that in the API? I had a look but couldn’t find  
anything…

Regards,  
Pierre

---

<div class="post-metadata">

**Author:** ![pierre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d07c76/32.png) [@pierre](https://www.ruby-forum.com/u/pierre)\
**Post date:** [April 10, 2009, 2:38pm UTC](https://www.ruby-forum.com/t/titled-border/165201/2 "2009-04-10T14:38:16Z")

</div>

Hi Pierre

Pierre P. wrote:

> 

The control you want is Wx::StaticBox (and also see Wx::StaticBoxSizer)

[http://wxruby.rubyforge.org/doc/staticbox.html](http://wxruby.rubyforge.org/doc/staticbox.html)

a

---

<div class="post-metadata">

**Author:** ![pierre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d07c76/32.png) [@pierre](https://www.ruby-forum.com/u/pierre)\
**Post date:** [April 14, 2009, 7:58am UTC](https://www.ruby-forum.com/t/titled-border/165201/3 "2009-04-14T07:58:12Z")

</div>

Alex F. wrote:

> Hi Pierre
> 
> Pierre P. wrote:
> 
> > 
> 
> The control you want is Wx::StaticBox (and also see Wx::StaticBoxSizer)
> 
> [http://wxruby.rubyforge.org/doc/staticbox.html](http://wxruby.rubyforge.org/doc/staticbox.html)
> 
> a

Thanks Alex, that was indeed the control I was looking for!  
Yet, somehow, I quite didn’t get how to use it.  
For instance if if I want to add an other control in it (ListBox,  
StaticText, whatever), it’ll also be in the top-left corner on the top  
of the border, instead of in it’s center.  
I guess I’m missing something really basic, I just couldn’t figure out  
yet what.

---

<div class="post-metadata">

**Author:** ![pierre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d07c76/32.png) [@pierre](https://www.ruby-forum.com/u/pierre)\
**Post date:** [April 15, 2009, 2:46am UTC](https://www.ruby-forum.com/t/titled-border/165201/4 "2009-04-15T02:46:42Z")

</div>

Awesome Alex!  
Thank to you it looks like I’ll have a great and productive day today  
🙂

Big thanks

---

<div class="post-metadata">

**Author:** ![pierre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d07c76/32.png) [@pierre](https://www.ruby-forum.com/u/pierre)\
**Post date:** [April 14, 2009, 1:31pm UTC](https://www.ruby-forum.com/t/titled-border/165201/5 "2009-04-14T13:31:38Z")

</div>

Pierre P. wrote:

> Thanks Alex, that was indeed the control I was looking for!  
> Yet, somehow, I quite didn’t get how to use it.  
> For instance if if I want to add an other control in it (ListBox,  
> StaticText, whatever), it’ll also be in the top-left corner on the top  
> of the border, instead of in it’s center.

With Sizer-based layouts (recommended) I’ve found it easier to use  
Wx::StaticBoxSizer to get a label round controls. I probably should have  
pointed you at this first. See the simple example below:

alex  
\_\_

require ‘wx’

Wx::App.run do  
frame = Wx::Frame.new(nil, :title =\> ‘staticbox demo’)  
panel = Wx::Panel.new(frame)  
sizer = Wx::StaticBoxSizer.new( Wx::VERTICAL, panel, ‘a label’)  
sizer.add( Wx::ListBox.new(panel), 1, Wx::ALL|Wx::GROW, 5 )  
panel.sizer = sizer  
frame.show  
end
