Skip to content

Instantly share code, notes, and snippets.

@ChristianGruen
Created March 19, 2014 10:16
Show Gist options
  • Save ChristianGruen/9638932 to your computer and use it in GitHub Desktop.
Save ChristianGruen/9638932 to your computer and use it in GitHub Desktop.
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class F extends JFrame {
JLabel label;
F() {
label = new JLabel("!") {
@Override
public void paintComponent(final Graphics g) {
super.paintComponent(g);
Font font = label.getFont();
FontMetrics fm = g.getFontMetrics(font);
System.out.println("Font: " + fm.getFont());
System.out.println("Size: " + font.getSize2D());
System.out.println("Height: " + fm.getHeight());
System.out.println("Ascent " + fm.getAscent());
System.out.println("Descent: " + fm.getDescent());
System.out.println("Leading: " + fm.getLeading());
System.out.println("Max Advance: " + fm.getMaxAdvance());
System.out.println("Max Ascent: " + fm.getMaxAscent());
System.out.println("Max Descent: " + fm.getMaxDescent());
dispose();
}
};
add(label);
pack();
setVisible(true);
}
public static void main(String... args) { new F(); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment