在 JFrame 内容被删除、重新验证和重新绘制后,如何使 Java JLabel 在 JFrame 上显示?

How do you make Java JLabel show on JFrame after JFrame content is removed, revalidated, and repainted?

我目前正在创建一个程序,我试图在 JLabel 从 "Yes" 清除后进入 JFrame 并按下 JOptionPane。目前,我无法让它工作。`ready = new JLabel("Are you ready?"); ready.setToolTipText("Are you ready to begin?");

    }

private class thehandler implements ActionListener { 
    public void actionPerformed(ActionEvent event) {
        String string = "";
        Object[] options1 = {"Yes","No"};

        if (event.getSource()==pname) {
            string=String.format("You entered the name, %s, is this correct?", event.getActionCommand());

         int n = JOptionPane.showOptionDialog(null, string, "Is this name correct?", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options1, null);

        if (n == JOptionPane.YES_OPTION) {
            getContentPane().removeAll();
            revalidate();
            repaint();
            add(credits);
            add(ready);
        }`

为了防止混淆,上面有更多代码,基本上在 public class window extends JFrame.

中声明了 private JLabel ready

在完成对 UI 的更改(删除并添加)后调用 revalidaterepaint