What is the best way to right align a button in a dialog window, regardless of the window's WindowSize?

Here is a resizable window to test on:

 Column[{"Here's some text text text text text text text", 
 WindowFrameElements -> {"ResizeArea"}, 
 WindowFrame -> "Normal"]

I would like the button to always be right aligned.

Some unsatisfactory solutions I thought of:

  • Put the button in an Item and right align. Then the right margin is determined by the Column size which can't easily be set in pixels.

  • Put the button in a Panel, right align it, and set a fixed size on the panel. Again, the size is determined by the panel size, not the window size.

Use case:

Suppose we need to create an alternative to MessageDialog. This new function, myMessageDialog, should take the WindowSize option, and the created notebook should respond to SetOptions[nb, WindowSize -> ...] The dialog buttons should always be aligned to the right edge of the window regardless of the window size.

  • $\begingroup$ Please explain further the problem with Item. Could you use Spacer to set a margin after converting pixels to printer's points? $\endgroup$
    – Mr.Wizard
    Jul 27, 2012 at 11:54
  • $\begingroup$ @Mr.Wizard Try it in the sample dialog I included and resize the window. The buttons don't keep on the right if you increase the window size, which would be the ideal solution. Also, as I said, the right margin is determined by the column size, which is difficult to set properly. Item sizes can only be set in ems, not pixels. I use the Item approach in the image uploader's history dialog, and on a Chinese version of Windows, the sizes are all messed up because of the unpredictability of the em width (different system font). $\endgroup$
    – Szabolcs
    Jul 27, 2012 at 11:56
  • $\begingroup$ @Mr.Wizard I have tried to solve this problem properly many times during the past few months, and never managed to come up with a solution I'm satisfied with, and which is flexible enough to allow resizable windows. $\endgroup$
    – Szabolcs
    Jul 27, 2012 at 11:57
  • $\begingroup$ Spacer uses pixels. An em is the width of the letter M, or something like that ... $\endgroup$
    – Szabolcs
    Jul 27, 2012 at 12:01
  • $\begingroup$ According to the docs: "Spacer[w] displays as a spacer w printer's points wide." -- if Spacer works as desired you can use that to set the margin, can you not? That's one problem down if so. $\endgroup$
    – Mr.Wizard
    Jul 27, 2012 at 12:03

1 Answer 1


This is unrefined, but I'll put it up as a proof of concept:

   Row[{"Here's some text text text text text text text"}, 
     ImageSize -> Dynamic[CurrentValue["WindowSize"] /. {x_, _} :> x - 15]],
   Item[ChoiceButtons[], Alignment -> Right]
  WindowFrameElements -> {"ResizeArea"}, WindowFrame -> "Normal"
  • $\begingroup$ Why do you say "unrefined"? I see nothing clumsy about it. $\endgroup$
    – DavidC
    Jul 27, 2012 at 12:41
  • $\begingroup$ @David thanks :-) I didn't test it with anything but this one example so I am not presenting this as a complete solution, just an illustration of a method. $\endgroup$
    – Mr.Wizard
    Jul 27, 2012 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.