I'm trying to lay out some radio buttons using BoxLayout, which aligns Components right next to each other vertically or horizontally. In other words, it makes them nice and neat. However, I'm running into the exception:
"BoxLayout can't be shared"
I have been aware of this exception for a long time, but I didn't expect it to arise in the situation it did:
//... other stuff ... gameModePanelLabel = new JLabel("Choose the type of game.", SwingConstants.CENTER); compVcompModeOption = new JRadioButton("Computer vs. Computer"); playVcompModeOption = new JRadioButton("Player vs. Computer"); playVplayModeOption = new JRadioButton("Player vs. Player"); gameModes = new ButtonGroup(); gameModes.add(compVcompModeOption); gameModes.add(playVcompModeOption); gameModes.add(playVplayModeOption); gameModePanel = new JPanel(new BoxLayout(gameModePanel, BoxLayout.PAGE_AXIS)); gameModePanel.setBorder(BorderFactory.createTitledBorder("Game Mode")); gameModePanel.add(gameModePanelLabel); //There exception occurs in this line, but I assume gameModePanel.add(compVcompModeOption); //that the three lines below it will also provoke gameModePanel.add(playVcompModeOption); //an exception gameModePanel.add(playVplayModeOption); //... and yet other stuff ..
I have no idea why I am getting this error, as I am only adding Components to a JPanel with a BoxLayout...
Will someone please point out my silly mistake?