Skip to content

Remove unexpected reverse of button order in method select #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/main/scala/introprog/Dialog.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,22 @@ object Dialog:
null, question, title, JOptionPane.OK_CANCEL_OPTION
) == JOptionPane.OK_OPTION

/** Show a selection dialog with `buttons`. Return a string with the chosen button text. */
/**
* Show a selection dialog with `buttons`. Return a `String` with the chosen button text.
*
* @param message text describing the choice to be made by the user
* @param buttons the sequence of buttons to be displayed in this dialog
* @param title the title of this dialog
* @return a `String` with the chosen button text
*/
def select(message: String, buttons: Seq[String], title: String = "Select"): String =
scala.util.Try{
val chosenIndex =
JOptionPane.showOptionDialog(null, message, title, JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE, null, buttons.reverse.toArray, null)
buttons(buttons.length - 1 - chosenIndex)
JOptionPane.showOptionDialog(
null, message, title, JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE, null, buttons.toArray, null
)
buttons(chosenIndex)
}.getOrElse("")

/** Show a color selection dialog and return the color that the user selected. */
Expand Down