When I try to run the file I get this error, amen't sure how to fix it.

Exception in thread "main" java.lang.IllegalArgumentException: illegal component
 position
        at java.awt.Container.addImpl(Container.java:1035)
        at java.awt.Container.add(Container.java:408)
        at EmailWindow.CreateContent(EmailWindow.java:65)
        at EmailWindow.<init>(EmailWindow.java:22)
        at Lab6a.main(Lab6a.java:10)

Heres my code sorry for lack of comments

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class EmailWindow extends JFrame implements ActionListener
{
	//Declaring the Components
	Container cpane;
	JPanel textPanel;
	JPanel labelPanel;
	JPanel textFieldPanel;
	JPanel buttonPanel;
	JPanel buttonPanel2;
	ColouredPanel p;
	JButton ok,exit;

	public EmailWindow()
	{
		JFrame frame = new JFrame();
		this.setTitle("My Frame");
		this.setSize(800, 800);
		this.setContentPane(CreateContent());
		//this.setJMenuBar(CreateMenu());
		this.setVisible(true);
	}

	public Container CreateContent()
	{
		cpane = new JPanel(new BorderLayout());
		textPanel = new JPanel(new BorderLayout());
		labelPanel = new JPanel(new GridLayout(2,0));
		textFieldPanel = new JPanel(new GridLayout(2,0));
		buttonPanel = new JPanel(new FlowLayout());
		buttonPanel2 = new JPanel(new GridLayout(1,0));
		p = new ColouredPanel(Color.white, "Nothing yet....");





		JLabel name = new JLabel("Name: ");
		JLabel email = new JLabel("E-mail Address: ");

		JTextField namefield = new JTextField(20);
		JTextField emailfield = new JTextField(40);

		ok = new JButton("OK");
		exit = new JButton("EXIT");

		ok.addActionListener(this);
		exit.addActionListener(this);

		labelPanel.add(name);
		labelPanel.add(email);

		textFieldPanel.add(namefield);
		textFieldPanel.add(emailfield);

		textPanel.add(labelPanel, BorderLayout.WEST);
		textPanel.add(textFieldPanel, BorderLayout.CENTER);

		buttonPanel2.add(ok);
		buttonPanel2.add(exit);

		buttonPanel.add(buttonPanel2, FlowLayout.RIGHT);

		cpane.add(textPanel, BorderLayout.NORTH);
		cpane.add(buttonPanel, BorderLayout.SOUTH);
		return cpane;

	}

	public void actionPerformed(ActionEvent e)
	{
		Object objectUsed = e.getSource();

		if(objectUsed instanceof JButton)
		{
			if(e.getSource() == ok)
			{

				p.changeText("Pressed Ok");
			}

			else
			{
				p.changeText("Press Exit");
			}
		}
	}
}

Any help much appericated

see this error occurs when you are trying to insert a component in a content pane which is full like a Panel or Frame in GridLayout or you are trying to insert more components in an unresizeable Frame or there is a fault in absolute positioning

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.