# Java Swing problem

**URL:** <https://forum.kirupa.com/t/java-swing-problem/127587>\
**Category:** Uncategorized\
**Created:** [November 4, 2004, 2:16pm UTC](https://forum.kirupa.com/t/java-swing-problem/127587 "2004-11-04T14:16:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![G111](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@G111](https://forum.kirupa.com/u/G111)\
**Post date:** [November 4, 2004, 2:16pm UTC](https://forum.kirupa.com/t/java-swing-problem/127587/1 "2004-11-04T14:16:14Z")

</div>

I’m having some trouble with the below Java and keep on getting these errors. This is the first time I have ever tried swing in Java and have only recently started using Java, any help/resources are very welcome.

```auto

java.lang.Error: Do not use ButtonFrame.add() use ButtonFrame.getContentPane().add() instead
        at javax.swing.JFrame.createRootPaneException(JFrame.java:465)
        at javax.swing.JFrame.addImpl(JFrame.java:491)
        at java.awt.Container.add(Container.java:307)
        at ButtonFrame.<init>(ButtonFrame.java:16)
        at ButtonFrame.main(ButtonFrame.java:21)
Exception in thread "main" 

```

My code -----------------------------------

```auto
import javax.swing.*;

public class ButtonFrame extends JFrame {
    JButton load = new JButton("Load");
    JButton save = new JButton("Save");
    JButton unsubscribe = new JButton("Unsubscribe");
    
    public ButtonFrame() {
        super("Button Frame");
        setSize(80, 170);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel pane = new JPanel();
        pane.add(load);
        pane.add(save);
        pane.add(unsubscribe);
        add(pane);
        setVisible(true);
}

    public static void main(String[] arguments) {
        ButtonFrame bf = new ButtonFrame();
    }
}

```

Thanks in advance for your time 🙂
