Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I add multiple JPanels to a JFrame?

843807Sep 8 2010 — edited Sep 8 2010
I've been trying to do my own little side project to just make something for me and my friends. However, I can't get multiple JPanels to display in one JFrame. If I add more than one JPanel, nothing shows up in the frame. I've tried with SpringLayout, FlowLayout, GridBagLayout, and whatever the default layout for JFrames is. Here is the code that's important:
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.*;


public class CharSheetMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		CharSheetFrame frame=new CharSheetFrame();
		abilityPanel aPanel=new abilityPanel();
		descripPanel dPanel=new descripPanel();
		frame.setLayout(new FlowLayout());

		

		
		abilityScore st=new abilityScore();
		abilityScore de=new abilityScore();
		abilityScore co=new abilityScore();
		abilityScore in=new abilityScore();
		abilityScore wi=new abilityScore();
		abilityScore ch=new abilityScore();
		

		frame.add(aPanel);
		frame.add(dPanel);
		
		
		frame.validate();
		frame.repaint();
		
		frame.pack();
		frame.setVisible(true);
		
	}

}
aPanel and dPanel both extend JPanel. frame extends JFrame. I can get either aPanel or dPanel to show up, but not both at the same time. Can someone tell me what I'm doing wrong?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 6 2010
Added on Sep 8 2010
2 comments
434 views