Display font in a grid : Font « 2D Graphics GUI « Java






Display font in a grid

   

import java.awt.Font;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main {
  public static void main(String[] args) {
    final int columnCount = 10;
    final int side = 25;
    final int[][] grid = new int[50][columnCount];

    JPanel panel = new JPanel() {
      public void paintComponent(Graphics g) {
        Font font = new Font("WingDings", Font.PLAIN, 14);
        g.setFont(font);
        int off = 0;
        for (int i = 0; i < 256 * 256; i++) {
          if (font.canDisplay((char) i) == false) {
            continue;
          }
          off++;
          grid[off / columnCount][off % columnCount] = i;
          int x = off % columnCount * side;
          int y = (off / columnCount) * side + side;
          g.drawString(Character.toString((char)i), x, y);

        }
      }
    };
    JFrame frame = new JFrame();
    panel.setSize(300, 300);
    frame.getContentPane().add(panel);
    frame.setSize(300, 300);
    frame.setVisible(true);
  }
}

   
    
    
  








Related examples in the same category

1.Ascii font pattern
2.A cache of the dynamically loaded fonts found in the fonts directory
3.Load font from ttf file
4.Outline Font paintOutline Font paint
5.Font paintFont paint
6.Font DerivationFont Derivation
7.Font centeredFont centered
8.Font ListFont List
9.FontDemo lists the system fonts and provides a sample of each one(Have some problems)
10.Finds and displays available fonts
11.Obtain FontMetrics of different fonts
12.Draw font inside a Rectangle
13.Create font from true type font
14.Wrap string according to FontMetrics
15.Draw base line and enclosing line for a font
16.List all Fonts