I am trying to build my own "Battleship" game and have problems with swing. I now read endless docs on oracle tutorials on LayoutManagers, but not any of them works as I understand them. They only add a few buttons, but never two individual panels.
JPanel Background = new JPanel();
Background.setLayout(new BoxLayout(Background, BoxLayout.X_AXIS));
panelPlayer = new JPanel();
panelPlayer.setBorder(BorderFactory.createLineBorder(Color.black));
panelPlayer.setSize(700, 600);
// PC Field
panelPc = new JPanel();
panelPc.setBorder(BorderFactory.createLineBorder(Color.black));
panelPc.setSize(700, 600);
//adding to frame
getContentPane().add(Background);
Background.add(panelPlayer);
Background.add(panelPc);
After that I have a loop thats adds 16x16 buttons in a JButton[] once for every panel.
How to get the two panels to show a table layout? I used GridLayout before, the grid works, but it always takes up the whole space of the frame, not of the Container or Panel or else. The panels are overlapping then. GridBagLayout just puts the buttons in a row and beyond the screen.