You can put any JComponents in a JOptionPane , I donβt see any restrictions there, JOptionPane is the same top-level container as JFrame , JDialog or JWindow , but unlike simple Top-Level Containers , JOptionPane implemented return events from the built-in functionality in the value Integer , meaning buttons YES , NO , OK , CANCEL and CLOSE too,
put all the jbuttons in an array
String[] buttons = { "Yes", "Yes to all", "No", "Cancel".... }; int returnValue = JOptionPane.showOptionDialog(null, "Narrative", "Narrative", JOptionPane.WARNING_MESSAGE, 0, null, buttons, buttons[i]); System.out.println(returnValue);
source share