Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Philip Brown Newsgroups: comp.lang.java.programmer Subject: Re: problem with java displaying unicode, under ms-windows Date: Sun, 22 Jul 2012 09:55:51 -0700 (PDT) Organization: http://groups.google.com Lines: 85 Message-ID: References: <096d855d-7df4-4591-a498-818ae0bb193c@googlegroups.com> NNTP-Posting-Host: 173.58.246.116 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1342976585 7210 127.0.0.1 (22 Jul 2012 17:03:05 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 22 Jul 2012 17:03:05 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.58.246.116; posting-account=CiEMKgoAAADyVniih7tiexmSpPX6JYhp User-Agent: G2/1.0 X-Received-Bytes: 4716 Xref: csiph.com comp.lang.java.programmer:16221 On Sunday, July 22, 2012 9:22:52 AM UTC-7, Knute Johnson wrote: > .... > I copied some text from www.mainichi.co.jp into Libre Office. I saved > the text as UTF-8. I used the program below to display it. It isn't > quite correct though, I get a dot before the text that wasn't on the web > page. Other than that it works fine. Interesting. But it breaks the concept of "write once run anywhere", to set a platform specific font. My issue centers on how to make it work WITHOUT that hack. As I mentioned, my program currently runs fine on MacOS, Solaris, linux, ..... I dont want any OS-specific code in my program (nor should I have to have any?!) btw: thanks to markspace for his code, but I'm using AWT. Kindasorta like Knute's code, but with plain Frame, not JFrame, as top. On Sunday, July 22, 2012 9:22:52 AM UTC-7, Knute Johnson wrote: > On 7/21/2012 10:31 PM, phil@bolthole.com wrote: > > Hi folks, > > I'm hoping someone can tell me the magic to get java (6 or 7) to display unicode chars under ms-windows? > > > > This is a standalone program, not an applet: > > > > http://bolthole.com/jdrill/jdrill2_3_1.jar > > > > The program itself works; I know this, because it displays fine under macos. > > Unfortunately, the exact same jar file displays empty boxes instead of nice kanji chars, under ms-windows. Using java version 6 or 7. > > > > Looking in the font properties type files, it seems like they are referencing ms-gothic and ms-mincho fonts. which ARE present on the system. > > I see ms-gothic and ms-mincho in Control panel->fonts > > And my browser successfully displays unicode pages such as > > http://www.mainichi.co.jp/ > > > > So... why isnt java displaying unicode properly??? > > > > Some years ago, it was neccessary to download a special "international" version of java on windows, to display 16-bit-wide fonts. > > but there does not even seem to be that option any more. > > So.. what should I do? > > > > I copied some text from www.mainichi.co.jp into Libre Office. I saved > the text as UTF-8. I used the program below to display it. It isn't > quite correct though, I get a dot before the text that wasn't on the web > page. Other than that it works fine. > > import java.awt.*; > import java.awt.event.*; > import java.io.*; > import java.nio.charset.*; > import javax.swing.*; > > public class test extends JPanel { > private char[] buffer = new char[256]; > private int n; > > public test() { > setPreferredSize(new Dimension(320,240)); > try { > FileInputStream fis = new FileInputStream("xxx"); > InputStreamReader isr = new InputStreamReader(fis,"UTF-8"); > n = isr.read(buffer,0,256); > isr.close(); > } catch (IOException ioe) { > ioe.printStackTrace(); > } > } > > public void paintComponent(Graphics g) { > g.setFont(new Font("MS Mincho",Font.PLAIN,12)); > g.drawChars(buffer,0,n,10,20); > } > > public static void main(String[] args) { > EventQueue.invokeLater(new Runnable() { > public void run() { > JFrame f = new JFrame(); > f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); > f.add(new test(),BorderLayout.CENTER); > f.pack(); > f.setVisible(true); > } > }); > } > }