Skip to content

Commit ed2ff93

Browse files
authored
Merge pull request #51 from EliasAAradsson/remove-button-reverse
Remove unexpected reverse of button order in method `select`
2 parents b2243b4 + 8ff117b commit ed2ff93

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/main/scala/introprog/Dialog.scala

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,22 @@ object Dialog:
3939
null, question, title, JOptionPane.OK_CANCEL_OPTION
4040
) == JOptionPane.OK_OPTION
4141

42-
/** Show a selection dialog with `buttons`. Return a string with the chosen button text. */
42+
/**
43+
* Show a selection dialog with `buttons`. Return a `String` with the chosen button text.
44+
*
45+
* @param message text describing the choice to be made by the user
46+
* @param buttons the sequence of buttons to be displayed in this dialog
47+
* @param title the title of this dialog
48+
* @return a `String` with the chosen button text
49+
*/
4350
def select(message: String, buttons: Seq[String], title: String = "Select"): String =
4451
scala.util.Try{
4552
val chosenIndex =
46-
JOptionPane.showOptionDialog(null, message, title, JOptionPane.DEFAULT_OPTION,
47-
JOptionPane.QUESTION_MESSAGE, null, buttons.reverse.toArray, null)
48-
buttons(buttons.length - 1 - chosenIndex)
53+
JOptionPane.showOptionDialog(
54+
null, message, title, JOptionPane.DEFAULT_OPTION,
55+
JOptionPane.QUESTION_MESSAGE, null, buttons.toArray, null
56+
)
57+
buttons(chosenIndex)
4958
}.getOrElse("")
5059

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

0 commit comments

Comments
 (0)