Contrary to expectations, the default button order in ChoiceDialog is “Cancel” on the left and “OK” on the right.
In this method, I create a dialogue that lists the Sex of the cattle (Cow, Heifer, Steer, etc.). Everything works fine using the default dialog box, except that the order of the buttons is the reverse of every other custom dialog box I created.
I figured the Java Design and Design Guide requires a dialog with OK on the left and Cancel on the right.
In any case, as the code below shows, I tried to set my own buttons. Changing the order in which they are added does not matter.
However, I may have the order that I am looking for if ButtonData.OTHER, but then I do not get the desired result (selected sex).
All I really want to do is change the order of the buttons and get the desired result.
public static final String getChoice_Sex()
{
String sex = "";
List<String> list_Sexs = LM_Constant.getList_Sexs();
ChoiceDialog<String> dialog = new ChoiceDialog<>(list_Sexs.get(0), list_Sexs);
dialog.setTitle("Sex");
dialog.setHeaderText("Please choose one.");
dialog.setContentText("From this list:");
Optional<String> result = dialog.showAndWait();
if (result.isPresent())
sex = result.get();
return sex;
}
gbear source
share