List of usage examples for javax.swing JOptionPane getOptions
public Object[] getOptions()
From source file:GettingJOptionPaneSelectionDemo.java
public static int getSelection(JOptionPane optionPane) { int returnValue = JOptionPane.CLOSED_OPTION; Object selectedValue = optionPane.getValue(); if (selectedValue != null) { Object options[] = optionPane.getOptions(); if (options == null) { if (selectedValue instanceof Integer) { returnValue = ((Integer) selectedValue).intValue(); }/*from w w w. ja va 2s. c o m*/ } else { for (int i = 0, n = options.length; i < n; i++) { if (options[i].equals(selectedValue)) { returnValue = i; break; // out of for loop } } } } return returnValue; }
From source file:MessagePopup.java
public static int getSelection(JOptionPane optionPane) { // Default return value, signals nothing selected int returnValue = JOptionPane.CLOSED_OPTION; // Get selected Value Object selectedValue = optionPane.getValue(); System.out.println(selectedValue); // If none, then nothing selected if (selectedValue != null) { Object options[] = optionPane.getOptions(); if (options == null) { // default buttons, no array specified if (selectedValue instanceof Integer) { returnValue = ((Integer) selectedValue).intValue(); }//w w w. j a v a2 s . c om } else { // Array of option buttons specified for (int i = 0, n = options.length; i < n; i++) { if (options[i].equals(selectedValue)) { returnValue = i; break; // out of for loop } } } } return returnValue; }