Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

entering unicode in swing fields  RSS feed

 
Fred Abbot
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I am working on a project where the client is written in swing
the server is ejbs etc... the users would like to be able to enter other charachters such as � which is alt +1+5+9
it comes up as a square i see here it works fine i also tried it in all microsoft programs and the only one it worked is WORD do i hae to import the fonts or something please let me know i am supposed to be in production next week
thank you
Fred
 
Fred Abbot
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi im not sure i understand i am using swing components the way i understand this it checks for the available fonts in my system how cani ensure it will use the right font to display the correct unicode characters
when i chang my font in notePad i get diffrent rersults how can i do that in java?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's simple enough. You simply need to select a font that supports the character you wish to use. LucidaSans will do the job.
Font unicode = new Font("LucidaSans", Font.PLAIN, 12);
jTextField1.setFont(unicode);
 
Fred Abbot
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx
 
Ashwin Desai
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Refer to the following article:
http://java.sun.com/j2se/1.3/docs/guide/intl/addingfonts.html
http://www.ibm.com/java/education/international-text/index.html

You need to have the font present on the system and an entry added to the fonts.properties to use it. But, JDK1.3 supports dynamic fonts. Thus, you can create a font dynamically by the following.
From SUN's own Release Notes:
File f = new File("Arial.ttf");
FileInputStream is = new FileInputStream(f);
Font font = Font.createFont(Font.TRUETYPE_FONT, is);
To load from an URL,
URL url = new URL("{font location"});
InputStream is = url.openStream();
Font font = Font.createFont(Font.TRUETYPE_FONT, is);
Hope this helps.
Ashwin.


[This message has been edited by Ashwin Desai (edited May 01, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!