16

Is there an element in Java (i.e. Swing/AWT or SWT) that is equivalent to the HTML element fieldset?

peterh
  • 11,875
  • 18
  • 85
  • 108
RedhopIT
  • 609
  • 2
  • 7
  • 20

3 Answers3

31

Create a Panel, create a titled border and you will be able to put inside all your field components.

JPanel panel = new JPanel();
panel.add(new JLabel("foo"));
panel.setBorder(BorderFactory.createTitledBorder("bar")); 
Pier-Alexandre Bouchard
  • 5,135
  • 5
  • 37
  • 72
6

Have a look at javax.swing.border.TitledBorder. You can set them on panels and are similar in appearance to HTML fieldsets.

Border titleBorder = new TitledBorder(new LineBorder(Color.RED), "Fieldset");

You could then add the border to your panel using the setBorder() method.

MC Emperor
  • 22,334
  • 15
  • 80
  • 130
Jeshurun
  • 22,940
  • 6
  • 79
  • 92
3

If you are using SWT than I think that org.eclipse.swt.widgets.Group is what you are looking for. It is a Composite (a block in HTML analogy) and it looks like a fieldset in HTML.

I can't speak for AWT and SWING however.

Adam Arold
  • 29,285
  • 22
  • 112
  • 207