Skip to content

Instantly share code, notes, and snippets.

@benjjo
Created April 21, 2020 20:11
Show Gist options
  • Save benjjo/e6f73edc38ea9a542b1f293d5ead3227 to your computer and use it in GitHub Desktop.
Save benjjo/e6f73edc38ea9a542b1f293d5ead3227 to your computer and use it in GitHub Desktop.
import javax.swing.JCheckBox;
import javax.swing.JOptionPane;
public class ConfirmDialog1b {
public static void main(String[] args) {
JCheckBox check = new JCheckBox("Tick me");
Object[] options = {'e', 2, 3.14, 4, 5, "TURTLES!", check};
int x = JOptionPane.showOptionDialog(null, "So many options using Object[]",
"Don't forget to Tick it!",
JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]);
if (check.isSelected() && x != -1) {
System.out.println("Your choice was " + options[x]);
} else {
System.out.println(":( no choice");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment