<div dir="ltr"><div style="font-family:arial,sans-serif;font-size:12.800000190734863px">I recently decided to start using Racket for my scripting and for the most part I've found the experience fun and productive. GUIs are another matter, and I'm mainly building the simple UIs I need by copying and modifying existing code. I am having one vexing problem that's driving me crazy however. I want to add a menu-bar% to an application I'm building. After failing repeatedly to do from the Racket Guide alone, I searched and found several examples but none of them succeeded in building a frame with a menu-bar. Assuming they were just buggy, I kept searching. </div>
<div style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div style="font-family:arial,sans-serif;font-size:12.800000190734863px">Finally I came upon a piece of Matthias Feldman's code—see attached—and it too failed to work as advertised. I'm using Racket <font face="arial, sans-serif"> (v5.92) </font>on a Mac Pro workstation with OS 10.9.1 and running ./bin/racket in Emacs, but I've also tried from a shell and on both of my workstation mac and laptop. Matthias says the code works fine for him. Does this code work for you? I have no trouble building UIs with editor-canvas%, panel%, button% classes, but menu-bars's are eluding me so far.</div>
<div style="font-family:arial,sans-serif;font-size:12.800000190734863px"><div><br></div><div><div><font face="courier new, monospace">;; Matthias Felleisen Sat, 21 Sep 2013 06:43:24 -0700</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">(define f (new frame% [label "Notes"] [width 400] [height 600]))</font></div><div><font face="courier new, monospace">(define my-canvas%</font></div><div><font face="courier new, monospace"> (class canvas%</font></div>
<div><font face="courier new, monospace"> (super-new)</font></div><div><font face="courier new, monospace"> (define/override (on-char . x)</font></div><div><font face="courier new, monospace"> (displayln x)</font></div>
<div><font face="courier new, monospace"> (define dc (send this get-dc))</font></div><div><font face="courier new, monospace"> (send dc set-scale 1 1)</font></div><div><font face="courier new, monospace"> (send dc set-text-foreground "blue")</font></div>
<div><font face="courier new, monospace"> (send dc draw-text "Use this window for notes" 10 10))))</font></div><div><font face="courier new, monospace">(define c (new my-canvas% [parent f]))</font></div><div>
<font face="courier new, monospace">(define t (new text%))</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace">(define mb (new menu-bar% [parent f]))</font></div><div>
<font face="courier new, monospace">(define m-edit (new menu% [label "Edit"] [parent mb]))</font></div><div><font face="courier new, monospace">(define m-font (new menu% [label "Font"] [parent mb]))</font></div>
<div><font face="courier new, monospace">(append-editor-operation-menu-items m-edit #f)</font></div><div><font face="courier new, monospace">(append-editor-font-menu-items m-font)</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">(send f show #t)</font></div></div></div></div>