Java 将JComponent添加到applet';s窗格

Java 将JComponent添加到applet';s窗格,java,swing,applet,jcomponent,Java,Swing,Applet,Jcomponent,我试图在按下按钮时将JComponent(例如标签)添加到小程序窗格中。我有以下代码: public class TestApplet extends JApplet { @Override public void init() { setLayout(new FlowLayout()); JButton bt = new JButton("hit it"); bt.addActionListener(new ActionL

我试图在按下按钮时将JComponent(例如标签)添加到小程序窗格中。我有以下代码:

public class TestApplet extends JApplet
{
    @Override
    public void init()
    {
        setLayout(new FlowLayout());
        JButton bt = new JButton("hit it");
        bt.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent ae)
            {
                // getContentPane().setFont(null);
                getContentPane().add(new JLabel("to the right"));
            }
        });
        add(bt);
    }
}
这不会使标签可见,除非我取消注释
getContentPane().setFont(null)

请告知如何正确显示标签。提前谢谢

getContentPane().add(new JLabel("to the right"));
this.revalidate();