Using the NumericShaper.Range enumeration to support the display of digits
import java.awt.Container;
import javax.swing.JFrame;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.font.FontRenderContext;
import java.awt.font.NumericShaper;
import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
import java.util.HashMap;
import javax.swing.JPanel;
public class Test extends JFrame {
public Test() {
Container container = this.getContentPane();
container.add("Center", new NumericShaperPanel());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(250, 120);
this.setVisible(true);
}
public static void main(String[] args) {
new Test();
}
}
class NumericShaperPanel extends JPanel {
private TextLayout layout;
public NumericShaperPanel() {
String text = "java";
HashMap map = new HashMap();
Font font = new Font("Mongolian Baiti", Font.PLAIN, 32);
map.put(TextAttribute.FONT, font);
map.put(TextAttribute.NUMERIC_SHAPING,
NumericShaper.getShaper(NumericShaper.Range.MONGOLIAN));
FontRenderContext fontRenderContext = new FontRenderContext(null, false,
false);
layout = new TextLayout(text, map, fontRenderContext);
}
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
layout.draw(g2d, 10, 50);
}
}
Related examples in the same category