This week's book giveaways are in the Cloud and AI/ML forums. We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line! See this thread and this one for details.
I'm trying to use the Unicode alarm clock symbol (23F0) in a project I've been building. I have a grid of JLabels and JPanels that works correctly, and the left column of the grid is a column of JLabels that are supposed to "hand off" the alarm clock as a method is called; one should have the alarm clock while the rest display a single hyphen (-). In all the reading I've done on this problem, I've been led to the conclusion that I had to set the font correctly in order for the symbol to display. I opened TextEdit (Apple's Notepad, essentially), opened the special character box, searched the Unicode number, found the clock, inserted it into a txt file, and looked at the font parameters. TextEdit shows the character in the Font "Apple Color Emoji" with "Regular" as the only style option, and a range of font sizes available, from which I chose 18 as probably appropriate. Here are the pertinent lines of code from my project:
I can see that the code is working, because every time the code is called, I get nothing where the clock is supposed to be. No strange symbols, no formatting anomalies, just an empty space. Does anyone have any idea why I can't make this single character appear in my app? I chose the Unicode character because it was supposed to be a matter of changing a single String instead of creating and using an Image; I need to have this thing done in a few days and I still have more important logic to tweak before then. I'm not even a fan of the way I have the Font called out as it is because I'm not sure if I'm going to be running this under Windows or Mac when the time comes (another reason I want to avoid adding an Image file to the problem). For what it's worth, the other all of the other text throughout the grid also has a font size of 18 and everything fits very well. Thanks for reading.
I don't think that UTF-8 is a font either, but anyway you can't use that font unless your computer already supports it. Here's what you can do: the GraphicsEnvironment class has a static method which returns an array of all available Fonts. So you can see what Fonts are actually usable by Java on your computer. Next, you need to determine which of those fonts can display the character you're interested in. And fortunately the Font class has a method which tells you whether it can display a particular character.
All things are lawful, but not all things are profitable.
posted 3 years ago
This seems like the most accurate way, but I'll have to try it later. I only have a few days left to make this useful, and I'm still testing and tweaking the GUI to make sure it works on whichever display I'm using at run time (could be anything from a 15" monitor to a 47" TV). Thanks for the info.
This is the code I was suggesting for your research. (When I ran it on my machine only 1 of 485 fonts got printed out as being able to display that character.)
posted 3 years ago
Thanks, Paul; you didn't have to write code for me. Anyhow, I think I've figured out my problem. "Apple Color Emoji" is a proprietary Apple font that is not a vector font, but rather a collection of images disguised as a font. If I switch the font to "Segoe UI Emoji" and run under Windows, I get a (considerably less interesting) clock as I was expecting at the beginning. The difference is that the Windows font is a standard grayscale vector font, which makes it universally usable (such as by Java or a web browser, etc.). Luckily, I have also determined today that I will be running the app in Windows, so I can just stick with that. Thanks again for your help.