Q:

How to get height of string / character in java?

I want to get the height of a string. Here is what i mean:
Say I have string : Hi , then I want the height(Hi) as the max height among all the characters in that string, so it will be the height of H. I saw few posts which said to use graphics to measure it, but i am not printing it, but i just want the height!
If I can get the height of character  then i will write a loop to see which is the highest height!
So either of the two is fine:
Get height of string(max height among all letters in string) or
Get height of specified letter!

A:

Just use the method GC#textExtent() to get a Point with the height and width of the text:
public static void main(String[] args)
{
    final Display display = Display.getDefault();
    final Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(1, false));

    GC gc = new GC(display);
    
    System.out.println(gc.textExtent("Hi").y);
    
    gc.dispose();
    
    shell.pack();
    shell.open();

    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

Javadoc:

Returns the extent of the given string. Tab expansion and carriage return processing are performed.
The extent of a string is the width and height of the rectangular area it would cover if drawn in a particular font (in this case, the current font in the receiver).

