1
$\begingroup$

Consider some test list that I call LongList:

LongList = Table["Some very-very long name", 300];

I would like to use ChoiceDialog to associate some parameter with an element of the list.

parameter = 
 ChoiceDialog["Choose the experiment:", LongList, 
  Appearance -> "Vertical" -> {Automatic, 1}]

This does not work properly: the dialog window has fixed height, and it is impossible to scroll, so the list does not fit the window: enter image description here

If changing Appearance -> "Vertical" -> {Automatic, 1} to Appearance -> "Vertical" -> {Automatic, 10}, I do not fix the problem but gain an additional one instead, coming from the fact that the width of the window stays the same. As a result, 1) only 4 buttons match the window, and 2) the buttons cannot be wide enough to fit the list elements properly: enter image description here

The documentation on ChoiceDialog is very poor and does not include any description about changing its design.

Could you please tell me how to fix this problem (either allow scrolling down or scrolling left-right, with wide enough buttons)?

$\endgroup$
2
  • $\begingroup$ Do you insist on using ChoiceDialog? What about using a dropdown menu with PopupMenu? $\endgroup$
    – Domen
    Commented Apr 12, 2023 at 12:50
  • $\begingroup$ @Domen : ChoiceDialog is the only option I know how to use, at least for some special examples. $\endgroup$ Commented Apr 12, 2023 at 12:53

1 Answer 1

6
$\begingroup$

From UX perspective, I strongly suggest using a drop-down menu with PopupMenu instead. The code below works the same as ChoiceDialog: It opens a pop-up dialog, then returns the selected value.

dropdownDialog[list_] := 
 DialogInput[{choice = ""}, 
  Column[{PopupMenu[Dynamic[choice], list], 
    Button["OK", DialogReturn[choice]]}]]

dropdownDialog[LongList]

enter image description here

If you insist on buttons, you can use DialogNotebook with "VerticalScrollBar".

buttonsDialog[list_] := 
  DialogInput[
   DialogNotebook[
    Grid[Partition[
      Table[With[{opt = opt}, 
        Button[opt, DialogReturn[opt], ImageSize -> Automatic]], {opt,
         LongList}], 4]]], WindowElements -> {"VerticalScrollBar"}, 
   WindowSize -> Medium];

buttonsDialog[LongList]

enter image description here

$\endgroup$

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.