Java swing -JPanel on JPanel没有显示出来

pin*_*ing 3 java user-interface swing jpanel

我试图将JPanel添加到另一个JPanel,但我遇到的问题是第二个Jpanel不会出现在第一个.
事情的基本结构如下 -
我有JPanel panel1一个BoxLayout并且凭借HorizontalBoxes而且VerticalBoxes我不断添加JComponents它.JComponents除第二个外,所有都出现在panel1上JPanel.第二个JPanel不会出现的代码如下 -

public class LabelMacroEditor extends JPanel implements PropertyChangeListener {

    private static final long serialVersionUID = 1L;
    private LabelMacroModel model;

    public LabelMacroEditor(LabelMacroModel bean) {

        this.model = bean;
        model.addPropertyChangeListener(this);
        setupComponents();
        validate();
        setVisible(true);
    }

    public void setupComponents()
    {
        Box allButtons =  Box.createVerticalBox();
        for(MacroModel macroModel : model.getMacroModelList())
        {
            LabelMacroEditorEditableEntity macroEditorEntity =  new LabelMacroEditorEditableEntity(macroModel);
            Box entityBox =  Box.createHorizontalBox();
            entityBox.add(macroEditorEntity.getUpButton());
            entityBox.add(Box.createHorizontalStrut(15));
            entityBox.add(macroEditorEntity.getMacroDetailsButton());
            entityBox.add(Box.createHorizontalStrut(15));
            entityBox.add(macroEditorEntity.getDownButton());

            allButtons.add(entityBox);
        }

        add(allButtons);
    }

    @Override
    public void propertyChange(PropertyChangeEvent arg0) {
        revalidate();
    }

}
Run Code Online (Sandbox Code Playgroud)

LabelMacroEditor通过将其添加到JFrame以独立方式进行测试,发现它看起来很好.我假设它与来冲突revalidate/setVisible等有关.
我错过了一些明显的东西吗

如果有需要JPanel,我可以发布更多代码LabelMacroEditor.

编辑:我添加的代码片段LabelMacroEditor如下 -

private final LabelMacroModel labelMacroModel;
private LabelMacroEditor labelMacroEditor;
//code to populate labelMacroModel
Box verticalBox  = Box.createVerticalBox();
// Add all other JComponents to verticalBox
labelMacroEditor = new LabelMacroEditor(labelMacroModel);
verticalBox.add(labelMacroEditor);
add(verticalBox);
Run Code Online (Sandbox Code Playgroud)

Per*_*hau 7

我重新判断你的第一个面板没有布局管理器,在这种情况下你需要使用setLayout();

要么

这是因为第二个面板里面没有任何东西,因此它的首选大小为0.尝试添加一个新的JTextArea(10,5); 它,看看会发生什么.