Java 自定义JPanel类不会显示在容器的BoxLayout中

Java 自定义JPanel类不会显示在容器的BoxLayout中,java,swing,intellij-idea,Java,Swing,Intellij Idea,从SCMain.java中选择的代码: public JPanel createContentPane() { //Create the content-pane-to-be. JPanel contentPane = new JPanel(new BorderLayout()); contentPane.setOpaque(true); return contentPane; } public JPanel populateContentPane() {

从SCMain.java中选择的代码:

public JPanel createContentPane() {
    //Create the content-pane-to-be.
    JPanel contentPane = new JPanel(new BorderLayout());
    contentPane.setOpaque(true);

    return contentPane;
}

public JPanel populateContentPane() {
    JPanel container = new JPanel();
    container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS));
    JPanel panel1 = new AddAccountForm(this, this.getInputSet());;
    JPanel panel2 = new JPanel();

    container.add(Box.createRigidArea(new Dimension(0, 5)));
    container.add(panel1);
    container.add(Box.createRigidArea(new Dimension(0, 5)));
    container.add(panel2);
    container.add(Box.createGlue());
    return container;
}

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread.
 */
private void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("Sole Commando v1.0");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Create and set up the content pane.
    frame.setJMenuBar(this.createMenuBar());
    frame.setContentPane(this.createContentPane());

    // Add split panels
    frame.add(populateContentPane(), BorderLayout.CENTER);

    frame.pack();
    //Display the window.
    frame.setSize(1080, 1080);
    frame.setVisible(true);
}
从AddAccountForm.java中选择的代码:

public class AddAccountForm extends JPanel implements ActionListener{
    AddAccountForm(SCMain main, Set<String> InputSet) {
        //Combobox setup

        setSize(300, 300);
        System.out.println(Arrays.toString(storeNameList.toArray()));
        submitButton.addActionListener(this);
    }

    public JPanel getAddAccountRoot() {
        return addAccountRoot;
    }

    private void createUIComponents() {
        // TODO: place custom component creation code here
        storeNames = new JComboBox();
    }
}
但是,当将其用作JPanel(上述SCMain.java代码中的panel1)并运行SCMain时,AddAccountForm GUI根本不会显示。
注意:JPanel AddAccountForm是在IntelliJ GUI Builder中创建的,但正如我前面所说的,它作为一个JFrame工作,因此代码必须是正确的。

要更快获得更好的帮助,请发布或。
SCMain new1 = new SCMain();
AddAccountForm new2 = new AddAccountForm(new1, new1.getInputSet());