Example usage for javax.swing JFrame getFontMetrics

List of usage examples for javax.swing JFrame getFontMetrics

Introduction

In this page you can find the example usage for javax.swing JFrame getFontMetrics.

Prototype

public FontMetrics getFontMetrics(Font font) 

Source Link

Document

Gets the font metrics for the specified font.

Usage

From source file:GettingFontMetrics.java

public static void main(String args[]) {
    JFrame f = new JFrame("JColorChooser Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    FontMetrics metrics = f.getFontMetrics(f.getFont());

    f.setSize(300, 200);/*from   w  ww .  j  a v  a2 s . c  om*/
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("JColorChooser Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    f.setSize(300, 200);/*  w w  w  .  j  a v a  2s  . c o  m*/
    f.setVisible(true);

    FontMetrics metrics = f.getFontMetrics(f.getFont());

    int widthX = metrics.charsWidth(new char[] { 'a', 'b' }, 1, 2);

    System.out.println(widthX);

}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("JColorChooser Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    f.setSize(300, 200);// w w  w  .  j  av a  2 s .  c o m
    f.setVisible(true);

    FontMetrics metrics = f.getFontMetrics(f.getFont());

    int widthX = metrics.charWidth((int) 'C');

    System.out.println(widthX);

}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("JColorChooser Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    f.setSize(300, 200);/*w  w  w  .  ja va2  s  .  c o m*/
    f.setVisible(true);

    FontMetrics metrics = f.getFontMetrics(f.getFont());

    int widthX = metrics.charWidth('X');

    System.out.println(widthX);

}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("JColorChooser Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    f.setSize(300, 200);/*from  w w  w  . ja v a 2 s .  c o m*/
    f.setVisible(true);

    FontMetrics metrics = f.getFontMetrics(f.getFont());

    int widthX = metrics.bytesWidth(new byte[] { 66, 67, 68, 69 }, 1, 2);

    System.out.println(widthX);

}