You add cancelButton to the panel using the BorderLayout.SOUTH constant:
panel.add(cancelButton, BorderLayout.SOUTH);
But where do you set up the BorderLayout panel layout? Since you never installed this container layout, it will use the default layout for JPanel, which is FlowLayout.
Solution: set the JPanel panel layout to BorderLayout to get the BorderLayout behavior.
, :
for (String text : options) {
JRadioButton option = new JRadioButton(text);
option.setActionCommand(text);
group.add(option);
panel.add(option);
}
JRadioButton JPanel . , JRadioButtons JPanel, , , GridLayout(1, 0) GridLayout(0, 1), , JPanel , , BorderLayout.CENTER.
okButton , .