【问题标题】:JOptionPane doesn't work correct in JPanelJOptionPane 在 JPanel 中无法正常工作
【发布时间】:2013-02-10 15:15:30
【问题描述】:

在我的游戏中,当我创建 JOptionalPane 时,单击“确定”按钮后,它会在面板上绘制对话框。下面是错误的图片。

错误前的JOptionPane:

JOptionPane 出错后,点击按钮“Yes”后

JOptionPane 是从扩展自 JComponent 的类创建的,在这行代码中:

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

【问题讨论】:

  • APerson241,A--C,非常感谢!
  • JOptionPane 运行良好,但您的代码中的其他地方有一个错误,可能是您绘制图形/绘制 JPanel 的方式。

标签: java swing graphics joptionpane


【解决方案1】:

我怀疑您的面板对paintComponent() 的实现未能调用super.paintComponent(),如Q&A 所示。

【讨论】:

  • 非常感谢!创建 JOptionPane 后,我调用了 repaint(),现在单击“是”后,JOptionPane 会在面板上绘制并快速删除
猜你喜欢
  • 2016-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-14
相关资源
最近更新 更多