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.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Unicode character problem

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 6108
157
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a guess, but how about changing the font to "UTF-8"?
 
Adam Nadeau
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never actually considered that "UTF-8" might be a valid font. Anyhow, I tried that, then tried UTF-16, but still nothing. Thanks for the idea.
 
Sheriff
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Knute Snortum
Sheriff
Posts: 6108
157
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I should have said "encoding".
 
Adam Nadeau
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.)
 
Adam Nadeau
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!