Sign in to follow this  
Peter Conn

A problem with Swing

Recommended Posts

Hiya I am using java to make a GUI application, and I swing is doing something it hasn't before...
		main = new JFrame("Application");
		JPanel listPanel = new JPanel();
		JPanel dataPanel = new JPanel();
		entries = new JList();
		JScrollPane scroller = new JScrollPane(entries);
		listPanel.add(BorderLayout.CENTER, scroller);
		forename = new JTextField(10);
		surname = new JTextField(10);
		main.getContentPane().add(BorderLayout.WEST, listPanel);
		main.getContentPane().add(BorderLayout.EAST, dataPanel);
		main.setSize(480, 320);

What happens now is that the two text fields are shown side by side and overlapping with the list, I thought that panels were ment to stop such things from happening. Any help?

Share this post

Link to post
Share on other sites
You need to apply some useful layout manager to dataPanel.

For full control you should also look into GridBagLayout. Somewhat complex to use, but allows full control over layout.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this