Alex Rivera | Logout

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

Asked 2009-01-10T20:14:58.420
60

Trying to build a GUI application in Java/Swing. I'm mainly used to "painting" GUIs on the Windows side with tools like VB (or to be more precise, Gupta SQLWindows... wonder how many people know what that is ;-)).

I can't find an equivalent of a Group Box in Swing...

With a group box, you have a square box (usually with a title) around a couple of related widgets. One example is a group box around a few radio buttons (with the title explaining what the radio buttons are about, e.g. Group Box entitled "Sex" with "Male" and "Female" radio buttons).

I've searched around a bit... the only way I found was to add a sub-pane, set the border on the sub-pane and then add all the widgets in the "group" to the sub-pane. Is there a more elegant way to do that?

Edit
Report

1 Answer

4

A Group box is just a set of 'logically grouped widgets'. This in the swing world is a JPanel.

Add your widgets to a JPanel.

Set its border type to 'Titled Border' and give the title, same as the name of the VB6 'frame'.

Voila. You have your group box.

answered 2009-01-10T21:02:56.340

Your Answer