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

Specify range of Fonts to use.  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that if I use HTML in my Label creation, I can use the Font tag to specify a range of Fonts to be used just like on an HTML page.
But what I am wondering is if there is a way to do this with the Font object in JAVA without going through some if else logic. I know I can create a Font[] object, but I don't want to go through some drawn out process of
if (font exists) { Set Font }
else
if (font exists) {set font }
else
...
I hope that makes sense.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, there is GraphicsEnvironment.getGraphicsEnvironment().getAllFonts()... that gets a Font[] of all the fonts Java can use on the system...
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nathan Pruett:
Well, there is GraphicsEnvironment.getGraphicsEnvironment().getAllFonts()... that gets a Font[] of all the fonts Java can use on the system...

Right, now what I am needing is to say:
if (preferedFont1) { Set Font }
else
if (preferedFont2) { Set Font }
else
if (preferedFont3) { Set Font }
But without the if else or a case switch. Something similar to HTML's Tag
<FONT face="Verdana, Arial, Helvetica, sans-serif"> So that there is an order to the system checks for. But I don't want to use HTML either.
I am probably out of luck, but I thought I might as well check here...
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... you could make a special subclass of label... pass it a list of comma-separated font names, tokenize that into an array of fonts in order, then set the font of the label to be the first font that is in the array as well as installed on the system. Something kinda like this:

[ March 19, 2003: Message edited by: Nathan Pruett ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!