Java examples for 2D Graphics:Font
Load ttf file for font
import java.awt.EventQueue; import java.awt.Font; import java.awt.FontFormatException; import java.awt.GraphicsEnvironment; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import java.io.InputStream; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.JTextField; import util.ReadWord; public class DictScreen { public void actionPerformed(ActionEvent arg0) { File font_file = new File(System.getProperty("user.dir") + File.separator + "src" + File.separator + "Bangla.ttf"); Font font;/* www .ja va 2 s .c o m*/ try { font = Font.createFont(Font.TRUETYPE_FONT, font_file); Font sizedFont = font.deriveFont(20f); // Font font = Font.createFont(Font.TRUETYPE_FONT, is); // Font font = new Font("Bangla",Font.PLAIN,15); // System.out.println("asdasdas"); String ip = input.getText(); output.setFont(sizedFont); String meaning = ReadWord.getWord(ip); output.setText(meaning); } catch (FontFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); input.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { File font_file = new File(System.getProperty("user.dir") + File.separator + "src" + File.separator + "Bangla.ttf"); Font font; try { font = Font.createFont(Font.TRUETYPE_FONT, font_file); Font sizedFont = font.deriveFont(20f); // Font font = Font.createFont(Font.TRUETYPE_FONT, is); // Font font = new Font("Bangla",Font.PLAIN,15); // System.out.println("asdasdas"); String ip = input.getText(); output.setFont(sizedFont); String meaning = ReadWord.getWord(ip); output.setText(meaning); } catch (FontFormatException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); } }