Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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:

CreateDialog[
 Column[{"Here's some text text text text text text text", 
         ChoiceButtons[]}], 
 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.

share|improve this question
    
Please explain further the problem with Item. Could you use Spacer to set a margin after converting pixels to printer's points? –  Mr.Wizard Jul 27 '12 at 11:54
    
@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). –  Szabolcs Jul 27 '12 at 11:56
    
@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. –  Szabolcs Jul 27 '12 at 11:57
    
Spacer uses pixels. An em is the width of the letter M, or something like that ... –  Szabolcs Jul 27 '12 at 12:01
    
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. –  Mr.Wizard Jul 27 '12 at 12:03
show 3 more comments

1 Answer

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

CreateDialog[
  Column[{
   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"
]
share|improve this answer
    
Why do you say "unrefined"? I see nothing clumsy about it. –  David Carraher Jul 27 '12 at 12:41
    
@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. –  Mr.Wizard Jul 27 '12 at 12:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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