Sign in to follow this  
Peter Conn

A problem with Swing

Recommended Posts

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

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
Antheus    2409
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