Handy way to add extra custom Option Buttons into a JOptionPane
private void showMyPopup()
{
//Object accessed iunside inner class must be final
final MyObject myo = new MyObject();
//Create Buttons
JButton btnOK = new JButton( “Ok” );
JButton btnCancel = new JButton( “Cancel” );
JButton btnPreview = new JButton( “Preview” );
Object[] options = new Object[]{btnOK, btnCancel, btnPreview};
//Create JOptionPane Object
JOptionPane jop = new JOptionPane(
myo, JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options );
//Create JDialog from JOptionPane Object
final JDialog jd = jop.createDialog( editorApp, “JOptionPane Tester” );
//Create ActionListener
ActionListener list = new ActionListener()
{
public void actionPerformed(ActionEvent ae){
if ( ae.getActionCommand().equals( “Ok” ) || ae.getActionCommand().equals( “Preview” ) )
{
//Do the Work when Preview or OK are pressed
myo.executePreview();
}
if ( ae.getActionCommand().equals( “Ok” ) || ae.getActionCommand().equals( “Cancel” ) )
{
//Close the Dialig when OK or Cancel Are pressed
jd.dispose();
}
}};
//Add ActionListners
btnOK.addActionListener( list );
btnCancel.addActionListener( list );
btnPreview.addActionListener( list );
//Show JDialog
jd.show();
}