# Lack of proper expansion using FlexGridSizer

**URL:** <https://www.ruby-forum.com/t/lack-of-proper-expansion-using-flexgridsizer/147524>\
**Category:** wxRuby\
**Created:** [September 2, 2008, 8:08pm UTC](https://www.ruby-forum.com/t/lack-of-proper-expansion-using-flexgridsizer/147524 "2008-09-02T20:08:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![carluva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/76d3ee/32.png) [@carluva](https://www.ruby-forum.com/u/carluva)\
**Post date:** [September 2, 2008, 8:08pm UTC](https://www.ruby-forum.com/t/lack-of-proper-expansion-using-flexgridsizer/147524/1 "2008-09-02T20:08:41Z")

</div>

I experienced a problem similar to this using GridBagSizer earlier today  
([Two issues using GridBagSizer - wxRuby - Ruby-Forum](http://www.ruby-forum.com/topic/164539#new)). The problem was resolved  
at that point by using a BoxSizer instead of the GridBagSizer, but now  
I’ve run into the same problem with a FlexGridSizer. In the top half of  
the attached image, I use a series of horizontal BoxSizers, each with a  
StaticText (proportion = 0) and a TextCtrl (proportion = 1). This fills  
up the space nicely, but I want the left sides of the TextCtrls to line  
up. Keeping the BoxSizers and changing the proportions to something  
like 1 and 4 instead of 0 and 1 works, but it leaves large gaps between  
the label and the textbox when the window is large and lets the textbox  
unnecessarily force the labels to wrap when the window is smaller.

Using a FlexGridSizer accomplishes the goal, but the TextCtrls no longer  
fill up the available space. The source looks something like this:

require ‘wx’  
include Wx

class AddPanel \< Panel  
DEFAULT\_FIELDS = [“A Label”, “Another Label”, “A third label”, “And so  
on…”]

def initialize(parent)  
super parent

```
@fields = {}
@field_panels = {}
@field_labels = {}
@field_textboxes = {}

@field_layouts = FlexGridSizer.new 2
set_sizer @field_layouts

DEFAULT_FIELDS.each do |label|
  @fields[label] = ''

  @field_labels[label] = StaticText.new self, :label => label
  @field_textboxes[label] = TextCtrl.new self, :value =>

```

@fields[label]

```
  @field_layouts.add @field_labels[label], 0, EXPAND
  @field_layouts.add @field_textboxes[label], 1, LEFT, 4

  ...
end

show

```

end

…  
end

In the larger Window, the following code is relevant:

@add\_panel = AddPanel.new @parent\_panel  
…  
@option\_layout = BoxSizer.new VERTICAL  
@option\_panel.set\_sizer @option\_layout  
…  
@option\_layout.add @add\_panel, 1, EXPAND  
@add\_panel.show  
…  
@option\_layout.layout

Any suggestions? The only other option I can think of is to use a  
single horizontal BoxSizer with two vertical BoxSizers inside–one with  
all of the StaticTexts on the left, and the other with all of the  
TextCtrls on the right. This could potentially cause mis-alignment  
between the labels and their corresponding fields (if a label gets  
forced to wrap), though, so I’d rather avoid it.

Thanks,  
Doug

---

<div class="post-metadata">

**Author:** ![carluva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/76d3ee/32.png) [@carluva](https://www.ruby-forum.com/u/carluva)\
**Post date:** [September 2, 2008, 9:01pm UTC](https://www.ruby-forum.com/t/lack-of-proper-expansion-using-flexgridsizer/147524/2 "2008-09-02T21:01:43Z")

</div>

Doug G. wrote:

> I experienced a problem similar to this using GridBagSizer earlier today  
> ([Two issues using GridBagSizer - wxRuby - Ruby-Forum](http://www.ruby-forum.com/topic/164539#new)). The problem was resolved  
> at that point by using a BoxSizer instead of the GridBagSizer, but now  
> I’ve run into the same problem with a FlexGridSizer. In the top half of  
> the attached image, I use a series of horizontal BoxSizers, each with a  
> StaticText (proportion = 0) and a TextCtrl (proportion = 1). This fills  
> up the space nicely, but I want the left sides of the TextCtrls to line  
> up.

…

> Any suggestions?

FlexGridSizer is the right type of sizer for that sort of layout.

Maybe look at FlexGridSizer#add\_growable\_col ?

[http://wxruby.rubyforge.org/doc/flexgridsizer.html#FlexGridSizer\_addgrowablecol](http://wxruby.rubyforge.org/doc/flexgridsizer.html#FlexGridSizer_addgrowablecol)

alex

---

<div class="post-metadata">

**Author:** ![carluva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/76d3ee/32.png) [@carluva](https://www.ruby-forum.com/u/carluva)\
**Post date:** [September 2, 2008, 9:15pm UTC](https://www.ruby-forum.com/t/lack-of-proper-expansion-using-flexgridsizer/147524/3 "2008-09-02T21:15:49Z")

</div>

Alex F. wrote:  
[snip]

> Maybe look at FlexGridSizer#add\_growable\_col ?  
> [snip]

Alex,

Thanks, that (combined with using the EXPAND flag when adding  
@field\_textboxes[label] to @field\_layouts) did the trick.

Doug
