How to hide fields and labels in CustomLayout

I have the following CustomLayout, how do I hide the username and the ‘User Name:’ label?

I know I can hide the field through the FieldFactory, but how do I hide the Label?
My guess would be using CSS and hide the element, but how do I do that?

Thank You

User name:
Password:

You need to add class names to the TR elements, and then toggle the visibility of them by adding/removing a stylename on the CustomLayout

i.e.


HTML:
<tr [b]
class="label"
[/b]>
<td align="right">User&nbsp;name:</td>
<td><div location="username"></div></td>
</tr>

Java:
CustomLayout.addStyleName("hide-labels");


CSS:
.hide-labels .label {
   display: none;
}

That should work, but didn’t have time to test.

Thank You!

That worked, except I had to remove the Style not add it, either way that’s what I needed, thank you!

Isn’t .setVisible(false) works on a label when being in a custom layout ?

Yes it does, but that only hides the field, it does not hide the table row and the label, so you’ll have the row and the label visible but the data will be empty if you set the .setVisible(false) in CustomLayout