For some reason my JPanels that I'm adding to the content JPanel are stretching vertically, instead of being the preferred size. Here's the code:
public static JPanel content;
public APP()
{
setLayout(new BorderLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setJMenuBar(new MenuBar());
content = new JPanel(new GridLayout(0, 8, 2, 2));
add(new JScrollPane(content, 22, 32), BorderLayout.CENTER);
pack();
setLocationRelativeTo(null);
setResizable(false);
setVisible(true);
addJPanel();
addJPanel();
}
public void addJPanel()
{
JPanel box = new JPanel();
box.setPreferredSize(new Dimension(100, 100));
box.setBackground(Color.BLACK);
content.add(box);
content.validate();
}
How can I keep them at a specific size when they're being added? Or at least keep them from stretching all the way across the content panel. I want them to be all the same size without changing their sizes as more panels are added.
*NOTE: addJPanel() allows me to dynamically add new panels into the content panel with a button or an action. It is only a test method, the real addition of panels come from an action called by the menu button.