14.10. The JOptionPane Component

Static methods in the JOptionPane class let you easily create modal dialogs to show messages (JOptionPane.showMessageDialog), to ask for confirmation (JOptionPane.showConfirmDialog), to let the user enter text or to choose among predefined options (JOptionPane.showInputDialog), or to choose among a variety of buttons (JOptionPane.showOptionDialog). Each of these methods either returns an int specifying which button was pressed or returns a String specifying the option selected.

Useful JOptionPane Methods

JOptionPane is a robust class defining 26 constants, 7 constructors, and 59 methods. We only present five static methods for creating messages and input dialogs. All five methods define the same first three arguments ...

Get Core Web Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.