# Confused about tab-panel usage with mred-designer's code

**URL:** <https://racket.discourse.group/t/confused-about-tab-panel-usage-with-mred-designers-code/3189>\
**Category:** Questions & Answers\
**Created:** [September 30, 2024, 3:30pm UTC](https://racket.discourse.group/t/confused-about-tab-panel-usage-with-mred-designers-code/3189 "2024-09-30T15:30:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shakeshuck](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@shakeshuck](https://racket.discourse.group/u/shakeshuck)\
**Post date:** [September 30, 2024, 3:30pm UTC](https://racket.discourse.group/t/confused-about-tab-panel-usage-with-mred-designers-code/3189/1 "2024-09-30T15:30:01Z")

</div>

I'm using mred-designer, and am confused as to how I am supposed to get children under the appropriate tabs. All the areas I have added appear under tabs-panel, but under the first tab only. The generated code looks like this:

```scheme
  (set! tab-panel-123843
    (new
     (class tab-panel%
       (super-new)
       (define child-panels '())
       (define/public
        (add-child-panel p label)
        (set! child-panels (append child-panels (list p)))
        (send this append label)
        (when (> (length child-panels) 1) (send this delete-child p)))
       (define/public
        (active-child n)
        (send this change-children
          (lambda (children) (list (list-ref child-panels n))))))
     (parent horizontal-pane-123316)
     (choices (list "Market Values" "Market Selections"))
     (callback (λ (tp e) (send tp active-child (send tp get-selection))))
     (style '())
     (enabled #t)
     (vert-margin 0)
     (horiz-margin 0)
     (border 0)
     (spacing 0)
     (alignment (list 'center 'center))
     (min-width 0)
     (min-height 0)
     (stretchable-width #f)
     (stretchable-height #t)))

```

All areas added with mred appear under the first tab, I can't work out how to get contents under the second tab. I have specified two 'choices', and there appears to be two tabs, but only one with children (trying to set active-child to 1 gives me an error).

Using add-child-panel creates a new tab (with contents), but I can't see how to add/change children under existing tabs? The interface won't let me create an empty tab-panel (i.e. no choices) in order to do add-child-panel from scratch.

I'm obviously missing something, so if someone could please point me in the right direction...

Thanks.

---

<div class="post-metadata">

**Author:** ![bakgatviooldoos](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/bakgatviooldoos/32/1381_2.png) [@bakgatviooldoos](https://racket.discourse.group/u/bakgatviooldoos)\
**Post date:** [September 30, 2024, 5:28pm UTC](https://racket.discourse.group/t/confused-about-tab-panel-usage-with-mred-designers-code/3189/2 "2024-09-30T17:28:53Z")

</div>

Hi, @shakeshuck.

I remember being confused by them as well, when I tried the first time.

I made a quick application in MrEd, so apologies for the terrible formatting.

[Crazy Tab Panels](https://gist.github.com/bakgatviooldoos/a7dc79415e488e50f2ca978a48491bfc)

It's just a button, and, a tab-panel with two tabs which, depending on the selection, adds a text field to either when the button is pressed.

The important bit, though, is the callback for the button, which does the adding:

```scheme
(the-button-callback
 (lambda (button control-event)
   ;; here I get the child (which is being set by `active-child`)
   (define selected-tab (first (send the-tab-panel get-children)))
   (new text-field%
        [parent selected-tab]
        [label (format "field #~a" (length (send selected-tab get-children)))])))

```

I hope that helps!

Edit: missing words

* * *

Edit: In case it is unclear (I now realize), the `active-child` procedure is called when the _callback_ for `the-tab-panel` is called (in turn when a tab is selected).

In particular, see [the tab-panel% docs](https://docs.racket-lang.org/gui/tab-panel_.html), where it states:

> The callback procedure is called (with the event type 'tab-panel) when the user changes the tab selection.

---

<div class="post-metadata">

**Author:** ![shakeshuck](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@shakeshuck](https://racket.discourse.group/u/shakeshuck)\
**Post date:** [October 1, 2024, 10:43pm UTC](https://racket.discourse.group/t/confused-about-tab-panel-usage-with-mred-designers-code/3189/3 "2024-10-01T22:43:23Z")

</div>

Thanks for this!  
The important bits for me are the class definitions to add panels to the correct tabs at startup - there's no way I would have thought of this, and it's something I can definitely use.

Now I just need to get the population process working, lol.  
Thanks again.

Edit: Even after making this comment, it has still taken me some time to realise that the panels listed in child-panels are supposed to be instantiated. I'm getting there slowly...!
