I am new to building GUIs with Java and for my first attempt I decided to create a Minesweeper clone. Everything was going great, until it came to generating the field tiles at run-time. I have a field JPanel (FlowLayout) that is large enough to contain 16*16 mine tiles, where each tile is a JPanel itself (CardLayout consisting of a label and a button on top of it). I managed to get the tiles to show up properly, but I have a small problem. After the 13th tile is added, every next tile moves the whole field panel to the right, along with some components above it, which are not part of the field panel itself. If I add all 256 tiles, the whole field goes somewhere off the screen and so do the components above it.
What is causing this and how can I fix it?
Here are some screenshots of the problem and the form design: