Java Swing Tutorial - Java FontMetrics.bytesWidth(byte[] data, int off, int len)








Syntax

FontMetrics.bytesWidth(byte[] data, int off, int len) has the following syntax.

public int bytesWidth(byte[] data,  int off,  int len)

Example

In the following code shows how to use FontMetrics.bytesWidth(byte[] data, int off, int len) method.

import java.awt.FontMetrics;
//  w w w.ja v a2  s.c  om
import javax.swing.JFrame;

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

    f.setSize(300, 200);
    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);
    
  }
}