Is there a "Group Box" equivalent in Java Swing?

Others have already commetned about JPanel and using a TitledBorder, that's fine.

However, when playing with Swing LayoutManagers, you may find it annoying that components in different JPanels cannot align correctly (each panel has its own LayoutManager).

For this reason, it is a good practice (check "JGoodies" on the web for more details) in Swing GUIs to NOT use TitledBorders but rather separate groups of components in a JPanel by a JLabel followed by a horizontal JSeparator.

Ref. "First Aid for Swing"


Create a JPanel, and add your radiobuttons to it. Don't forget to set the layout of the JPanel to something appropriate.

Then call panel.setBorder(BorderFactory.createTitledBorder(name));