Source Code : Using the NumericShaper.Range enumeration to support the display of digits

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

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);
  }
}

 

Thank with us