Mega Code Archive

 
Categories / Java Tutorial / Swing
 

Option Pop-Ups

With the option pop-up, the return value is an int. If the button labels are manually specified with a non-null argument, the integer represents the selected button position. import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JOptionPane; public class AddingIconsToOptionPopups {   public static void main(String[] a) {     JFrame frame = new JFrame();     Icon greenIcon = new ImageIcon("yourFile.gif");     Icon redIcon = new ImageIcon("");     Object iconArray[] = { greenIcon, redIcon };     JOptionPane.showOptionDialog(frame, "Continue printing?", "Select an Option",         JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, iconArray, iconArray[1]);   } }