Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a component's baseline in Java

Very simple question:

What is a component's baseline in Java?

The documentation does not provide an answer as to what the "baseline" is, just describes its use by LayoutManagers. Yes, the answer is probably straightforward, but I don't want to play the guessing game.

like image 961
Max K Avatar asked Jun 21 '16 17:06

Max K


1 Answers

From JavaDocs of FontMetrics

When an application asks to place a character at the position (x, y), the character is placed so that its reference point (shown as the dot in the accompanying image) is put at that position. The reference point specifies a horizontal line called the baseline of the character. In normal printing, the baselines of characters should align.

More formally a component's baseline is an imaginary line on which text is placed in a component. In general it is the distance in pixels between top-left of the component and Text's baseline. So in order to get this baseline one needs to pass height and width of the component. It is not necessary for every component to have baseline and for those components this method returns -1.

This method is used during component layout, so it can not use actual dimensions at that point because component is still being resized/repositioned. Hence it needs width and height to be passed.

For your reference as @Frakcool mentioned:

Line under "Find What:" is baseline.

like image 100
Sanjeev Avatar answered Oct 31 '22 23:10

Sanjeev