I have an application using a JDesktopPane and I am using JOptionPane.showInternalConfirmDialog() to get confirmation from the user. The issue I am having is that no matter what I use as the parent, I always get the coffee cup as the frame icon. See example code (without try-catch):
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setSize(300, 300);
frame.setIconImage(ImageIO.read(new File("icon.png")));
JDesktopPane dp = new JDesktopPane();
frame.add(dp);
frame.setVisible(true);
if(JOptionPane.showInternalConfirmDialog(frame.getContentPane(),
"Are you sure?", "Confirm", JOptionPane.YES_NO_OPTION) == 0)
{
//Do something
}
This is what I get:

If I use the frame as the parent instead of using getContentPane() I get this exception:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
Would appreciate any insight into this issue.
EDIT: I am aware of the workaround of creating a new internal frame as follows:
JOptionPane jop = new JOptionPane("Are you sure?", JOptionPane.YES_NO_OPTION);
JInternalFrame inf = jop.createInternalFrame(frame, "Confirm");
inf.setFrameIcon(icon);
inf.setVisible(true);
But then the window is no longer modal, which I need it to be.
As per the docs, you can pass an
Iconas a parameter to theshowInternalConfirmDialogmethod. Just remember to also then add all the rest of the parameters in the correct order.