How do I add multiple JPanels to a JFrame?

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?

In the future, Swing related questions should be posted in the Swing forum.
You need to read up on [How to Use Layout Managers|http://download.oracle.com/javase/tutorial/uiswing/layout/index.html]. The tutorial has working example of how to use each layout manager.
By default the content pane of the frame uses a BorderLayout.
For more help create a [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://sscce.org], that demonstrates the incorrect behaviour.
The code you posted in NOT a SSCCE, since we don't have access to any of your custom classes. To do simple tests of adding a panel to frame then just create a panel, give it a preferred size and give each panel a different background color so you can see how it works with your choosen layout manager.

Similar Messages

  • How do I add multiple apple id's to one account

    How do I add multiple Apple id's to one account for billing and Icloud use?

    You don't. You can't combine Apple IDs.

  • How do I add multiple contacts to a group?

    How do I add multiple contacts to a group on my Ipad?

    See if this thread helps.
    https://discussions.apple.com/thread/4114588
    Matt

  • How do i add multiple email addresses to my calendar

    How do I add multiple email addresses to my calendar on my iphone

    You can create an email alias at the mail feature at iCloud.com

  • HT201317 how can I add multiple photos to camera roll

    how can I add multiple photos to camera roll

    If you mean from photo stream, open your photo stream album on your phone in the thumbnail view, tap Edit, tap all the photos to select them, tap Share, then tap Save to Camera Roll.

  • How do I add multiple apple ids to my computer iTunes

    How do I add multiple apple ids to my computer iTunes account

    You can authorize more than one account.
    iTunes Store: Authorize or deauthorize your Mac or PC

  • How do i add multiple hp 8600 printers to one account

    how do i add multiple hp 8600 printers to one account

    Hi rexdalehub,
    If you are referring to the ePrint Center, you can simply choose "Add a printer" to the right of your current printers tab.
    I was an HP employee.
    Reminder: Please select the "Accept as Solution" button on the post that best answers your question. Also, you may select the "Kudos" button on any helpful post to give that person a quick thanks.

  • How do you add multiple iTunes to Keynote

    How do you add multiple songs from the iTunes to your Keynote presentation?

    Jer&Renee,
    welcome to Apple Discussions.
    It depends where you want them in your presentation.
    Open the Media inspector and choose a playlist. In the list of entries, mark those you want to add to Keynote (use command-click to mark multiple titles not in one block).
    Then drag the marked titles either on a slide or on the small Audio field (looks like a frame) in Document inspector. When you then hover the cursor at the Audio "frame", you'll see the quick info "Multiple Files". You cannot change the order or remove one of the files, but only all of them.

  • How do I add multiple addresses/contacts in an email tread to my contact list without having to enter each at a time?

    How do I add multiple addresses/contacts in an email tread to my contact list without having to enter each at a time? I have AppleScript but don't see "add address" in any of the boxes/drop-downs. 

    Sorry, but Address Book does not allow you to select more than one email address to send to in a group. There's really no reason why people need multiple copies of a message, anyway; they have the option of forwarding email to another email address of theirs.
    Mulder

  • How do I add multiple iPads to my Apple ID

    How do I add multiple ipads to my Apple ID

    Should just plug it into iTunes and go. You'll just likely need to give each one a different name. That's what i did when I added my iPad to my iTouch on iTunes.
    When you plug them into the computer, give each  a different name and choose to either make them clones of each other (back up XXXX profile onto this iPad) or set each up as a new iPad.

  • HT1040 How do I add multiple different pictures to my order?

    How do I add multiple pictures to my order? It wants me to check out after each one!

    With the amount of information you've provided it's impossible to offer a potential solution.  We can't see your computer so we need to know the details of your problem and setup, i.e.:
    what version of iPhoto are you using?
    what system version are you running?
    can you post a screenshot of the order window?
    OT

  • How can I add multiple email addresses to Address Book?

    How can I add multiple email addresses to Address Book?
    Can it be done from an .xlsx file?

    I have tried that, but the system reads the emails as one long email and I can't find any way of separating them - it ignores spaces, colons and I have also tried putting them through a word doc... still does not work. It works perfectly easily on a PC system!! ( I have just moved to a mac!)
    any ideas would be good
    thanks

  • How do I add multiple email addresses i have received (900) to my address book instead of doing it one by one?

    how do I add multiple email addresses i have received (+ -900) to my address book instead of having to do it one by one?

    Grab them all and drag them to the Address Book.
    Roger

  • How do I add multiple URL's to a Bookmarks folder?

    Safari question:  How do I add multiple URL's to a Bookmarks folder?

    Ok...
    Click the Bookmarks icon  left side of the Safari toolbar then select Boomarks in the sidebar.
    Locate the folder then try dragging url's to that folder that way.
    If that doesn't work, from your Safari menu bar click Bookmarks >  Add Bookmark then click the, "Add this page to" pop up menu then select the folder you want to save that url to.

  • How can I add multiple email addresses  from spreadsheet into email?

    how can I add multiple email addresses  from spreadsheet into email?

    I have tried that, but the system reads the emails as one long email and I can't find any way of separating them - it ignores spaces, colons and I have also tried putting them through a word doc... still does not work. It works perfectly easily on a PC system!! ( I have just moved to a mac!)
    any ideas would be good
    thanks

Maybe you are looking for