3

I am able to write Hindi, Urdu in JTextPane, but not able to write other Indian regional languages in text pane. I have also downloaded the font for these languages, but it doesn't work.

How to write Indian regional languages like Gujrati, Punjabit etc in JTextPane?

UPDATE :

A piece of code as requested :

public class NewClass { 

    public static void main(String args[]) { 

        JFrame j = new JFrame("Hello!"); 
        j.setSize(200, 200); 
        JTextPane k = new JTextPane(); 
        k.setFont(new Font("Shree-Guj-0768W", Font.PLAIN, 17));
        j.add(k); j.setVisible(true); 

    }

} 

I have set the gujrati(a Language) font in jtextpane, the existing content appear in gujrati,but when i write in the jtextpane boxes appears. Can we have multiple indian regional languages in same Jtextpane?

Pratik
  • 30,639
  • 18
  • 84
  • 159
Mayank Singh
  • 109
  • 1
  • 11
  • If you ask your answer with your own code then it is easy to get more accurate answer as you want – Rajshri Dec 27 '12 at 07:07
  • public class NewClass { public static void main(String args[]) { JFrame j = new JFrame("Hello!"); j.setSize(200, 200); JTextPane k = new JTextPane(); k.setFont(new Font("Shree-Guj-0768W", Font.PLAIN, 17)); j.add(k); j.setVisible(true); } } i have set the gujrati font in jtextpane, the existing content appear in gujrati,but when i write in the jtextpane boxes appears. Can we have multiple indian regional languages in same Jtextpane? – Mayank Singh Dec 27 '12 at 08:42

2 Answers2

10

First thing is to install the font.

Secondly set the font for JTextPane - for e.g if you want to set Shivaji05 font for typing Marathi in JTextPane then use:

jTextPane1.setFont(new java.awt.Font("Shivaji05", Font.PLAIN, 11)); 
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Rajshri
  • 4,163
  • 2
  • 15
  • 17
  • 2
    Don't use 'magic numbers' like '0' for the font style. Better to use `Font.PLAIN` (or another constant or an addition of them). – Andrew Thompson Dec 27 '12 at 07:14
  • 1
    *"First thing is to install the font."* +1 See also [this answer](http://stackoverflow.com/questions/8364787/how-do-you-import-a-font/8365030#8365030) to "How do you import a font?". – Andrew Thompson Dec 27 '12 at 07:19
  • i have set the gujrati font in jtextpane, the existing content appear in gujrati,but when i write in the jtextpane boxes appears. Can we have multiple indian regional languages in same Jtextpane? – Mayank Singh Dec 27 '12 at 08:39
  • Do you really need a `JTextPane` at all? Is this styled (bold, italic, headers, paragraphs, embedded images..) text it is displaying? Or can it be done purely with the font (and perhaps a bold/italic variant of that `Font`)? – Andrew Thompson Dec 27 '12 at 10:50
4

You need to set the font for JTextPane.

Here is the link below how you can set the font and used it

http://www.javaprogrammingforums.com/java-swing-tutorials/39-how-change-jtextarea-font-font-size-color.html

http://javatechniques.com/blog/setting-jtextpane-font-and-color/

Pratik
  • 30,639
  • 18
  • 84
  • 159
  • 1
    The font must have install in the system and if the font was found then it'll be support for write those languages. – Pratik Dec 27 '12 at 07:04