
import javax.swing.*;
import java.awt.*;
import java.util.Locale;

public class FontViewer {

    public static void main(String[] args) {
        // Set default locale to Japan
        Locale.setDefault(Locale.JAPAN);

        // code points to test with the font
       final int[] CODE_POINTS = new int[] { 0x1200, 0xa901, 0x1400 };

       String textToDisplay = new String(CODE_POINTS, 0, CODE_POINTS.length);

        // Get all available font names
        String[] fontNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

        // Create the main frame
        JFrame frame = new JFrame("Font Viewer");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(500, 400);
        frame.setLayout(new BorderLayout());

        // Create a JList to display the fonts
        JList<String> fontList = new JList<>(fontNames);
        fontList.setCellRenderer(new FontCellRenderer(textToDisplay));
        JScrollPane scrollPane = new JScrollPane(fontList);
        frame.add(scrollPane, BorderLayout.CENTER);

        // Display the frame
        frame.setVisible(true);
    }

    // Custom cell renderer to display each font in its own style
    static class FontCellRenderer extends DefaultListCellRenderer {
        private final String textToDisplay;

        public FontCellRenderer(String textToDisplay) {
            this.textToDisplay = textToDisplay;
        }

        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            String fontName = (String) value;
            Font font = new Font(fontName, Font.PLAIN, 20);
            label.setFont(font);
            label.setText(fontName + ": " + textToDisplay);
            return label;
        }
    }
}
