# Make frame dynamically size to contents?

**URL:** <https://www.ruby-forum.com/t/make-frame-dynamically-size-to-contents/129551>\
**Category:** wxRuby\
**Created:** [February 19, 2008, 3:14pm UTC](https://www.ruby-forum.com/t/make-frame-dynamically-size-to-contents/129551 "2008-02-19T15:14:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![s0nspark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f475e1/32.png) [@s0nspark](https://www.ruby-forum.com/u/s0nspark)\
**Post date:** [February 19, 2008, 3:14pm UTC](https://www.ruby-forum.com/t/make-frame-dynamically-size-to-contents/129551/1 "2008-02-19T15:14:22Z")

</div>

What magic and/or code should I use to cause a frame to adjust to fit  
the contents? When I change label text, for example… The docs led me  
to believe this is done automatically but that doesn’t seem to be the  
case… Surely I’ve missed something. 🙂

I’m using sizers for the layout and loading from an xrc, BTW…

Thanks!  
Tim

---

<div class="post-metadata">

**Author:** ![s0nspark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f475e1/32.png) [@s0nspark](https://www.ruby-forum.com/u/s0nspark)\
**Post date:** [February 20, 2008, 10:54am UTC](https://www.ruby-forum.com/t/make-frame-dynamically-size-to-contents/129551/2 "2008-02-20T10:54:05Z")

</div>

Tim F. wrote:

> What magic and/or code should I use to cause a frame to adjust to fit  
> the contents? When I change label text, for example… The docs led me  
> to believe this is done automatically but that doesn’t seem to be the  
> case… Surely I’ve missed something. 🙂  
> Try Window#set\_sizer\_and\_fit(a\_sizer) or Sizer#fit(a\_window)

[http://wxruby.rubyforge.org/doc/window.html#Window\_setsizerandfit](http://wxruby.rubyforge.org/doc/window.html#Window_setsizerandfit)  
[http://wxruby.rubyforge.org/doc/sizer.html#Sizer\_fit](http://wxruby.rubyforge.org/doc/sizer.html#Sizer_fit)

hth  
alex

---

<div class="post-metadata">

**Author:** ![s0nspark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f475e1/32.png) [@s0nspark](https://www.ruby-forum.com/u/s0nspark)\
**Post date:** [February 20, 2008, 5:52pm UTC](https://www.ruby-forum.com/t/make-frame-dynamically-size-to-contents/129551/3 "2008-02-20T17:52:25Z")

</div>

Alex F. wrote:

> Tim F. wrote:
> 
> > What magic and/or code should I use to cause a frame to adjust to fit  
> > the contents? When I change label text, for example… The docs led me  
> > to believe this is done automatically but that doesn’t seem to be the  
> > case… Surely I’ve missed something. 🙂  
> > Try Window#set\_sizer\_and\_fit(a\_sizer) or Sizer#fit(a\_window)
> 
> [http://wxruby.rubyforge.org/doc/window.html#Window\_setsizerandfit](http://wxruby.rubyforge.org/doc/window.html#Window_setsizerandfit)  
> [http://wxruby.rubyforge.org/doc/sizer.html#Sizer\_fit](http://wxruby.rubyforge.org/doc/sizer.html#Sizer_fit)
> 
> hth  
> alex

Thanks Alex …

One odd thing I notice is that the sizer seems to squash everything  
really close together. I added small spacers (2-4 pixels) between  
controls to try and pad things out a bit but they seem to be ignored…  
I also tried increasing the border sizes on the controls themselves  
without success. Any idea what I’m not doing correctly?

Cheers,  
Tim

---

<div class="post-metadata">

**Author:** ![s0nspark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f475e1/32.png) [@s0nspark](https://www.ruby-forum.com/u/s0nspark)\
**Post date:** [February 20, 2008, 8:55pm UTC](https://www.ruby-forum.com/t/make-frame-dynamically-size-to-contents/129551/4 "2008-02-20T20:55:57Z")

</div>

Tim F. wrote:

> One odd thing I notice is that the sizer seems to squash everything  
> really close together. I added small spacers (2-4 pixels) between  
> controls to try and pad things out a bit but they seem to be ignored…

Borders are definitely the way to go in most cases, not spacers. Are you  
using XRC or pure ruby? If using pure ruby, check that you have included  
Wx::ALL or Wx::LEFT or Wx::TOP in the third argument to Sizer#add, to  
indicate which side of the control you wish to add a border to.

See bigdemo/wxSizer.rbw for a demonstration of some of the options.

If using XRC, check that you have ticked the box to specify which side  
you want to add a border to. In DialogBlocks, it usually sets a default  
border of 5 on each side.

alex

---

<div class="post-metadata">

**Author:** ![s0nspark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f475e1/32.png) [@s0nspark](https://www.ruby-forum.com/u/s0nspark)\
**Post date:** [February 20, 2008, 9:51pm UTC](https://www.ruby-forum.com/t/make-frame-dynamically-size-to-contents/129551/5 "2008-02-20T21:51:57Z")

</div>

Alex F. wrote:

> Borders are definitely the way to go in most cases, not spacers. Are you  
> using XRC or pure ruby? If using pure ruby, check that you have included  
> Wx::ALL or Wx::LEFT or Wx::TOP in the third argument to Sizer#add, to  
> indicate which side of the control you wish to add a border to.
> 
> See bigdemo/wxSizer.rbw for a demonstration of some of the options.
> 
> If using XRC, check that you have ticked the box to specify which side  
> you want to add a border to. In DialogBlocks, it usually sets a default  
> border of 5 on each side.
> 
> alex

Turns out I was fine … I was just requiring the old version of the  
frame I did in code rather than the code that loaded XRC I was editing  
:-p

Thanks for the help in any case…

Cheers,  
Tim
