Random MrEd Tips

This contains some random tips for accomplishing things with MrEd that aren’t immediately obvious from reading the manual. So far there’s only one tip. Some day there may be more.

Aligning Text Boxes

When stacking two or more text boxes, it looks nicer if the left edge of the boxes line up. Here’s an example of what happens by default:

Screen shot
(define top
  (new frame%
       (label "Top")
       (style '(no-resize-border))
       (border 10)))

(define text1
  (new text-field%
       (label "Name")
       (parent top)
       (callback void)))

(define text2
  (new text-field%
       (label "Address")
       (parent top)
       (callback void)))

(send top show #t)

The left edges of the boxes are not aligned, making the dialog look slightly untidy.

Getting them to line up is simple. When laying out a control, MrEd calculates the width of the label given at instantiation. If the label is later changed, the window is updated with the new text, but the width is not. To align the edges, instantiate all of the controls with the same label (the longest one you plan to use), and then use set-label to change them to what they should be.

Screen shot
(define top
  (new frame%
       (label "Top")
       (style '(no-resize-border))
       (border 10)))

(define text1
  (new text-field%
       (label "Address")
       (parent top)
       (callback void)))
(send text1 set-label "Name")

(define text2
  (new text-field%
       (label "Address")
       (parent top)
       (callback void)))

(send top show #t)

This should work for any control with a label on the left. Now if I can only figure out how to right justify a label…

Don’t Panic!

August 18, 2003. Pat Ekman
Luxuriantly handcrafted using only the finest XHTML.