javauser-interfacegrouplayout

What Exactly Does "Alignment.BASELINE" mean in a Java GroupLayout?


I'm learning about GroupLayout in Java.

Alignment.LEADING, CENTER, and TRAILING makes sense to me,

but I have no idea what BASELINE means.

Where do the components get positioned if I indicate Alignment.BASELINE?

I know that this is a very basic question, but can anyone please help me?

Thanks in advance.


Solution

  • Alignment.BASELINE works for components which renders a textual information (e.g. JLabel, JButton, etc). With Alignment.BASELINE alignment, the GroupLayout will align such components so that the baseline of their text stays on the same (horizontal) line (makes for an easier reading, the eye doesn't need to jump up/down on the virtual line of text).

    See Java Swing tutorial - GroupLayout - specifically the 'Vertical Layout' section.