I am getting insane! I am adding a JPanel to an another JPanel by a method. This method is generating a grid via SpringLayout. The problem is that after adding all JComponents to the panel the preferred size of the panel is 0, thus no content is displayed. Using an another layout manager solves the visibility but I need the structures of the SpringLayout. I can't find my problem.
private JPanel panelErzeugen(ArrayList<JComponent> labels){
JPanel panel = new JPanel();
SpringLayout layout = new SpringLayout();
panel.setLayout(layout);
int abstandVert = 5;
int abstandHori = 5;
for(JComponent label : labels){
if(labels.indexOf(label) == labels.size()/2){
abstandVert = 100;
abstandHori = 5;
}
layout.putConstraint(SpringLayout.WEST, panel, abstandVert, SpringLayout.WEST, label);
layout.putConstraint(SpringLayout.NORTH, panel, abstandHori, SpringLayout.NORTH, label);
panel.add(label);
abstandHori = abstandHori + 25;
}
return panel;
}