Joe
Joe

Reputation: 45

I'm having trouble setting up a jpanel and frame

I'm pretty new to swing and am having some troubles. Heres my code. I'm getting the error

Exception in thread "main" java.lang.IllegalArgumentException: adding container's parent to itself at java.awt.Container.checkAddToSelf(Container.java:472) at java.awt.Container.addImpl(Container.java:1083) at java.awt.Container.add(Container.java:410) at UMSL.Eval.createUserInterface(Eval.java:126) at UMSL.Eval.(Eval.java:95) at UMSL.Eval.main(Eval.java:56) Java Result: 1

Can anyone explain to me what this error message is trying to tell me and how I can make things work.

  private void createUserInterface()
{


  JPanel contentPane;

   contentPane = new JPanel();



JPanel instructorPanel = new JPanel();
instructorPanel.setBounds(40, 20, 276, 48);
instructorPanel.setBorder (BorderFactory.createEtchedBorder() );
instructorPanel.setLayout( null) ;
instructorPanel = new JPanel();
contentPane.add(instructorPanel);
  // set up Instructor Label
JLabel instructorLabel = new JLabel();
instructorLabel.setBounds (25, 15, 100, 20);
instructorLabel.setText("Instructor:");
instructorLabel.add (instructorLabel);

Upvotes: 1

Views: 128

Answers (1)

fdsa
fdsa

Reputation: 1409

Like @Reimeus said, you're trying to add a label to itself with the line instructorLabel.add (instructorLabel); I'm assuming that you're trying to add the label to the instructor panel which would be instructorPanel.add(instructorLabel);

Upvotes: 1

Related Questions