Search code examples
javaswinggraphicsjoptionpane

JOptionPane doesn't work correct in JPanel


In my game, when I create a JOptionalPane, after I click on the "Ok" button, it draws the dialog over the panel. Below are pictures of the error.

JOptionPane before the error:

enter image description here

JOptionPane after the error, after click on the button "Yes"

enter image description here

The JOptionPane is created from class who extends from JComponent, in this line of code:

JOptionPane.showConfirmDialog(getParent().getParent(),
        "The end! Lifes = 0");

Solution

  • I suspect that your panel's implementation of paintComponent() fails to invoke super.paintComponent(), as shown in this Q&A.