I was trying to indent some rows with the layout set to
layout.labelAlignment( LabelAlignment.RIGHT );
The indentation is only working with LEFT alignment.
This should be mentioned in:
In my opinion all examples with strings having the same length could benefit from changing them to 'real world' strings:
This would have shown me that the indent example was using LEFT alignment.
Well, in fact, we cannot really say that indent() works only with left alignment. I'd rather say that it seems to work a bit differently when using right alignment.
The notion of indent is just extra space added on the left of a row, or more precisely, as mentioned in the javadoc, space added before the left most component of a row.
In the case of grids, the labels in the label column (the 1st column of the grid) are, initially, all forced to the same width (the max width of all labels in the column). Then extra space is added when rows are indented.
When you use right-alignment, the indent space most often won't clearly be visible to the end user.
However, there are situations where this indent will appear as expected:
layout.row().left().add(new JLabel("Address"), new JSeparator()).fill();
layout.row().grid(new JLabel("Street 1")).indent(1).add(new JTextField("Benjamin Franklin Bd"));
layout.row().grid(new JLabel("Zip Code")).indent(1).add(new JTextField("CA 1234"));
In the example above, when using right alignment, you will see that "Zip Code" is indented in comparison with "Address". You would see no indent at all when not using indent(1).
I thank you for your reply. But I think to add a row out of the canonical grid to get an indent should not be the way to "solve" this for a user of this library.
I think the second line should also be starting at the postion where the first line is starting, if I use this example:
layout.row().left().add( new JLabel( "Out of the canonical grid..." ) );
layout.row().grid( new JLabel( "Label 1:" ) );
layout.row().grid( new JLabel( "Label 2:" ) ).indent( 4 ).add( new JTextField( "field 2" ) );
layout.row().grid( new JLabel( "Label 3:" ) ).indent( 4 ).add( new JTextField( "field 3" ) );
For me, your last example gives the expected result.
The reason is that there is only ONE canonical grid, and all "grid()" rows belong to it.
Non-canonical grid rows (left, right, center and bar) share no dimension with grid rows and are completely independent of grid rows.
In a canonical grid, there is one specific label column, which size is fixed and equal to the max width of all labels in that column,
plus the max indents added to grid rows.
Hence, in your example, the first column of the first grid row ("Label 1:") is the same width as 1st column of grid rows "Label 2: " and "Label 3:" which are indented 4 times.
Now, since the alignment of labels is right, "Label 1:" will be right-aligned in this column and will thus appear indented, compared with the 1st row, out of the canonical grid.
Not an improvement to DGL library but rather a task to improve the documentation.
Considered minor, because I don't think many people will see the observed behavior problematic when using indent() with right alignment for labels.
Documentation updated on SVN trunk (rev. 520).
Documentation fixed in release 1.10