ddgamer
asked on
WingDings Font Problem
I am having trouble getting any type of symbol font to display properly. I have tried both WingDings and Symbol. Currently the code I have does the following.
1 -Starts by putting the font in the defaults table for later lookup by the app
defaults.put("symbols.font ", new FontUIResource("WingDings" , Font.BOLD, 16));
2 - Grabs the font at a later point from the defaults table
Font symbolsFont = (Font)UIManager.get("symbo ls.font");
3 - Sets the font and draws some text with it
The problem is that anything drawn shows up as an open square. For whatever reason it appears not to recognize the font.
How do I remedy this problem and make sure it doesn't happen on end-users machines?
Thanks.
1 -Starts by putting the font in the defaults table for later lookup by the app
defaults.put("symbols.font
2 - Grabs the font at a later point from the defaults table
Font symbolsFont = (Font)UIManager.get("symbo
3 - Sets the font and draws some text with it
The problem is that anything drawn shows up as an open square. For whatever reason it appears not to recognize the font.
How do I remedy this problem and make sure it doesn't happen on end-users machines?
Thanks.
ASKER
I am calling the get because the setting of "symbols.font" is just something I do in the defaults for me so I can access it from other classes and not worry about changing it in 100 places if I need to.
A) I am pretty sure. I don't know how to tell but if I do a println(symbolsFont) it states WingDings along with the attributes I set after my call to get.
B) The problem is on my development machine which is windows, and yes the users will be also.
A) I am pretty sure. I don't know how to tell but if I do a println(symbolsFont) it states WingDings along with the attributes I set after my call to get.
B) The problem is on my development machine which is windows, and yes the users will be also.
OK. I wonder if its a CharacterEncoding problem - have you *ever* seen the WingDings appear in your Java guis?
ASKER
Nope, but I haven't tried before either.
Tell me what you see on the command line when you run this:
public class WingDing {
public static void main(String[] args) throws Exception {
System.out.println(Class.f orName("su n.awt.wind ows.CharTo ByteWingDi ngs"));
}
}
public class WingDing {
public static void main(String[] args) throws Exception {
System.out.println(Class.f
}
}
ASKER
class sun.awt.windows.CharToByte WingDings
OK, that's a good sign - stay tuned!
OK, I've had the same problem, hence the commented-out line in paint() down below. This is a mixture of a kludge and a more portable solution! The WingDingFrame is somewhat redundant - I changed my mind about what I was going to do. Please ask if you need more comment:
import java.awt.*;
import java.awt.event.*;
public class WingDing {
public static void main(String[] args) throws Exception {
//System.out.println(Class .forName(" sun.awt.wi ndows.Char ToByteWing Dings"));
WingDingFrame wdf = new WingDingFrame("This is a test!");
wdf.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
wdf.setSize(300,300);
wdf.setVisible(true);
}
}
class WingDingFrame extends Frame {
public WingDingFrame(){
super();
}
public WingDingFrame(String s){
super(s);
WingDingPanel wdp = new WingDingPanel();
add(wdp);
}
class WingDingPanel extends Panel {
public void paint(Graphics g){
super.paint(g);
//g.setFont(new Font("WingDings", Font.BOLD, 16));
g.drawString("\u270E\u2702 \u2701\u26 0E\u2706\u 2709\u231B \u2328",10 ,50);
}
}
}
// Unicode-WingDings at http://www.csn.ul.ie/~caolan/wingdings/proposal/
import java.awt.*;
import java.awt.event.*;
public class WingDing {
public static void main(String[] args) throws Exception {
//System.out.println(Class
WingDingFrame wdf = new WingDingFrame("This is a test!");
wdf.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
wdf.setSize(300,300);
wdf.setVisible(true);
}
}
class WingDingFrame extends Frame {
public WingDingFrame(){
super();
}
public WingDingFrame(String s){
super(s);
WingDingPanel wdp = new WingDingPanel();
add(wdp);
}
class WingDingPanel extends Panel {
public void paint(Graphics g){
super.paint(g);
//g.setFont(new Font("WingDings", Font.BOLD, 16));
g.drawString("\u270E\u2702
}
}
}
// Unicode-WingDings at http://www.csn.ul.ie/~caolan/wingdings/proposal/
What were you doing with the WingDings anyway?
ASKER
I am developing a program where I need to replace letters with various symbols or shapes. I'll have a look at the link and example and get back to you.
ASKER
Hmmm ... it seems to work okay for displaying my wingding type fonts. But, it only works if I never call setFont() on the graphics context -- which means both my wingding characters are too small, and my other characters are in the wrong font.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hmm ... looks like I'll have to experiment since if I use the SansSerif font it works fine. Thanks.
Thanks. My example works equally well with a serif font actually.
ASKER
Yeah, but when I specify Lucida Sans is when it doesn't work for me for a lot of the characters.
as opposed to defaults.get(). In any case are you sure that:
a) symbolsFont is holding a reference to a WingDings font
b) Your users are running Windows