
var eMenuItem new JMenuItem ('Exit', exitIcon) tMnemonic (KeyEvent.VKE) A menu object consists of menu items. In our case, the menu can be opened with the Alt + F shortcut. To bind a menu to a particular key, we use the setMnemonic () method. JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane. The menus can be accessed via keyboard as well. Int input = JOptionPane.showConfirmDialog(null, panel, "Admin Rights Confirmation", UIManager.put("OptionPane.minimumSize", new Dimension(300, 120)) tHorizontalAlignment(SwingConstants.CENTER) JLabel label2 = new JLabel("Are you sure you want to continue?") tVerticalAlignment(SwingConstants.BOTTOM) JLabel label1 = new JLabel("This file requires administrator rights.") ImageIcon icon = new ImageIcon("src/images/lock64.png") The showConfirmDialog() will bring up a dialog with the options Yes, No and Cancel and the title “Select an Option”:

(In some older versions of Java you might get a compiler error when using primitive types directly)


The showConfirmDialog() can be called using the following combinations of parameters:Ĭomponent, Object, String, int, int, Icon This method is a quick and easy way to get user input by asking a confirming question, like yes/no/cancel. This is a review of the showConfirmDialog() method of JOptionPane Class.
