user550738
user550738

Reputation:

how to get the bottom position of the font on a swing widget?

I am working on a little drag-and-drop Java GUI builder.

I'm dragging and dropping JLabels and JButtons on a panel and it's working fine.

Now I want the widgets to be aligned "correctly" next to each other based on the bottom of the font on the widget.

If I line them up at yPosition = 0, it looks like this:

My Label /-----------\
         | My button |
         \-----------/

But I need to line them up at yPosition = "bottom of their text", like this:

         /-----------\
My Label | My button |
         \-----------/

So my question is: Given a JLabel or a JButton, how can I determine the yPosition coordinate of the bottom of the font on that widget?

I hope that's clear. Any help is greatly appreciated!

Thanks, Rob

Upvotes: 1

Views: 47

Answers (1)

kleopatra
kleopatra

Reputation: 51525

The method you are looking for is

component.getBaseline(...)

Upvotes: 2

Related Questions