[EDIT] this happend on OSX with Java 1.5! (but may also happen on Windows!)
It seems japanese users of my Java Swing program cannot write japanese symbols in JTextFields. Actually they can write them but do not see them. They only see blocks which somehow indicates I think that the font does not support these symbols.
I set my own font for various reasons ("Lucida Sans", Font.PLAIN, 12) - which I wouldn't like to change. My questions are:
would the JTextFields show japanese Symbols without me setting this Font?
could I detect which Locale's are fully supported by my Font and only set it in those cases but leave the standard Java font for all other cases like Locale.Japan?
do you have any other suggestions?
Thank you for your help!
would the JTextFields show japanese Symbols without me setting this Font?
Most likely since the JRE will choose the default.
could I detect which Locale's are fully supported by my Font and only set it in those cases but leave the standard Java font for all other cases like Locale.Japan?
Yes, in theory, although easier would be to test if this font can display a locale specific character using the the canDisplay(char) method in Font. If it don't, you may switch to the default.
do you have any other suggestions?
Here's a link on this topic that may help
Do you have a link for your product?
For this very reason, my internationalized application sets its font depending on the locale. To answer your questions:
This probably depends on which version of Windows is being used. Is this the US edition with Japanese fonts installed, or is this the version sold in Japan? I don't know the exact answer to your question, but I expect that the answer is, "It depends."
I don't know of any standard way to do this. I have found a wonderful utility for investigating this kind of thing: BabelMap. This will tell you exactly what characters are supported by any given font.
Other suggestions: Set your font depending on Locale, at least for select Locales.
Related
Recently, I have attempted to create a textbox that uses a custom font. The problem I had with it though, is that it also requires certain enters in several places. At first, I tried using \n or \r\n, but that didn't work. This lead me to using HTML, but this gave me the problem of my font not loading in. I tried to fix this using several methods, including change the style of the HTML body, like this:
<html><body style="font-family: pixelmix">Text</body></html>
The font in question, pixelmix is an imported font, not installed on the PC. It is, however, known to the program and can be used without HTML. I don't know if HTML can work with uninstalled fonts, but if anyone had any idea on how to get enters AND a custom font, please let me know.
Does anyone know of an existing solution for font glyph fallthrough in Java? For example, our designers have decided that Calibri is the font that mostly fits our needs, but if I specify Calibri, it can naturally not render characters that do not have a matching glyph in that font. In that case, I would need it to fall through to a second specified font, and if all else fails - use one of Java's logical fonts.
Has anyone come up with a solution for this, which can be plugged into existing Swing components without having to write custom Swing components for the entire project?
This is a very old project already, and building custom graphical components is not a feasible solution.
This isn't a code-based solution and probably won't be of much help, since it requires each user to install a file locally, but just in case...
You can add fallback fonts in a special directory within the JRE installation. From the Java documentation:
Users can add a physical font as a fallback font to logical fonts used in Java 2D rendering by installing it in the lib/fonts/fallback directory within the JRE.
I work with Eclipse & Java.
System.getProperty("file.encoding") == "GBK".
All my Swing UI Labels stored in separate properties files(like messages_ru.properties,messages_sc.properties).
I use native2ascii to convert properties files to get the Unicode.
But one strange thing comes, the label show the Russian correctly,but not correct with the Simple Chinese. My OS supports Simple Chinese.
Anyone has the same question or has some suggestions to find the Reason? If you need more information, I can show you.
Hmm... Find the reason,it is cause by the Font, My app is using the Factory Font("Calibri") which is not support for Simple Chinese.
I have some Swing code (written in 1.6 for 1.6) that specifically sets the font in a text area to Courier, but on some Windows systems, this shows up as Arial (the system default?) instead. Does that mean a font is missing from the system? What is the behavior Java has when it can't find a font it is looking for? Does it complain? Does it log it somewhere? Does it immediately resort to using the system default? Is the behavior different between 1.4/1.5/1.6 versions of the JVM?
Has anyone else ever run into this? I was very surprised to have something different from what I HARDCODED into the application show up in the UI - and only on some systems. The core issue is that I need a monospaced font style for this particular case, and Arial is not monospaced. Is there some way to specify a fallback if a certain font is not found? Something like:
if font is available use "Courier"
else use "monospaced"
???
You should first check if "Courier" is among the results of GraphicsEnvironment.getAvailableFontFamilyNames()
I don't know any built-in mechanism in Java for "if-unavailable-fallback-to" behavior.
According to this article1 the only monospaced TrueType fonts shipped by Microsoft are Courier New and Lucida Sans Typewriter.
It might expect you to specify "Courier New" for Courier. I don't have a Windows system, so I can't verify this.
I extend org.eclipse.swt.widgets.Composite and create many widgets on it, (labels, table, text etc). The problem I am facing is that the labels' text is getting truncated on linux while it appears fine on windows. When I change the linux's font to gothic the truncation is little less but still there. Is there way to homogenize the windows and linux display. What could be the best font to use in linux in such a case.
More likely it is related to this eclipse bug which I just lobbied to have re-opened: https://bugs.eclipse.org/bugs/show_bug.cgi?id=151322
It sounds like you are using absolute positioning instead of dynamic layouts. (If this isn't the case, perhaps you could post code demonstrating the problem). Using a dynamic layout should ensure that controls are resized to accommodate their contents. (They're also great if you ever translate a product, because then you don't have to rejig every dialog for every language.)
To complete McDowel's answer, there is also a bug related to the way Linux check for wrapping label:
It is fixed since 3.4M7.
Even though it may not be related to your case, it would be useful to know which version of eclipse you are using and if you can reproduce your bug with the latest ones (like a 3.5M6)