Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent in Java for fieldset (HTML)?

Tags:

java

swing

awt

swt

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

like image 647
RedhopIT Avatar asked May 30 '12 16:05

RedhopIT


People also ask

What is Fieldset in HTML?

<fieldset>: The Field Set element. The <fieldset> HTML element is used to group several controls as well as labels ( <label> ) within a web form.

Can I have Fieldset inside Fieldset?

The fieldset element can also contain nested fieldset elements. This is normally only required in complex forms, where there are subgroups of form elements inside larger groupings. In this example, a fieldset for your profile includes a nested fieldset for contact details.

How do I set the width of a Fieldset in HTML?

A fieldset is as large as the parent container, just like any block-level element, if you do not give it a fixed width. So you have to make it display: inline-block . Show activity on this post.


2 Answers

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")); 
like image 152
Pier-Alexandre Bouchard Avatar answered Sep 20 '22 13:09

Pier-Alexandre Bouchard


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.

like image 28
Jeshurun Avatar answered Sep 19 '22 13:09

Jeshurun