[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

WingDings Font Problem

Posted on 2002-07-17
15
Medium Priority
?
1,023 Views
Last Modified: 2013-12-02
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("symbols.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.
0
Comment
Question by:ddgamer
  • 8
  • 7
15 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 7160261
If you've done 1., then I'm not sure why you're calling Font symbolsFont = (Font)UIManager.get("symbols.font");
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
0
 

Author Comment

by:ddgamer
ID: 7160270
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7160284
OK. I wonder if its a CharacterEncoding problem - have you *ever* seen the WingDings appear in your Java guis?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ddgamer
ID: 7160312
Nope, but I haven't tried before either.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7160324
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.forName("sun.awt.windows.CharToByteWingDings"));
  }

}
0
 

Author Comment

by:ddgamer
ID: 7160357
class sun.awt.windows.CharToByteWingDings
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7160363
OK, that's a good sign - stay tuned!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7160466
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.windows.CharToByteWingDings"));
    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\u260E\u2706\u2709\u231B\u2328",10,50);
    }
  }

}
// Unicode-WingDings at http://www.csn.ul.ie/~caolan/wingdings/proposal/
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7160479
What were you doing with the WingDings anyway?
0
 

Author Comment

by:ddgamer
ID: 7160546
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.
0
 

Author Comment

by:ddgamer
ID: 7161013
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.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 400 total points
ID: 7161114
Not sure why you should have a problem here. This example uses 'all' the Unicode WingDing-like symbols. You can use the table at the very least:

import java.awt.*;
import java.awt.event.*;
import java.util.Random;

public class WingDing {
  final static int STRING_LENGTH = 10;
  final static char[] UNICODE_SYMBOLS = {
    '\u2701','\u2702','\u2706','\u2707','\u2708',
    '\u2709','\u270c','\u270d','\u2713','\u2717',
    '\u271e','\u2720','\u2721','\u272a','\u2730',
    '\u2734','\u2735','\u2736','\u273f','\u2740',
    '\u2744','\u274d','\u2751','\u2752','\u2756',
    '\u275d','\u275e','\u2780','\u2781','\u2782',
    '\u2783','\u2784','\u2785','\u2786','\u2787',
    '\u2788','\u2789','\u278a','\u278b','\u278c',
    '\u278d','\u278e','\u278f','\u2790','\u2791',
    '\u2792','\u2793','\u27a1','\u27a2','\u27a5',
    '\u27a6','\u27a9','\u27b3'
  };

  public static void main(String[] args){
    Frame f = new Frame();
    WingDingPanel wdp = new WingDingPanel();
    f.add(wdp);
    f.addWindowListener(new WindowAdapter(){
      public void windowClosing(WindowEvent e){
        System.exit(0);
      }
    });
    f.setSize(300,300);
    f.setVisible(true);
  }

  static class WingDingPanel extends Panel {
    public void paint(Graphics g){
      super.paint(g);
      g.setFont(new Font("SansSerif", Font.BOLD, 32));
      /**
       * Generate random symbol string of STRING_LENGTH characters.
       * This will, of course, change as the Frame is resized.
       */
      StringBuffer sb = new StringBuffer(STRING_LENGTH);
      Random r = new Random();
      for(int i= 1;i <= STRING_LENGTH ;i++){
        int n = r.nextInt(UNICODE_SYMBOLS.length);
        sb.append(UNICODE_SYMBOLS[n]);
      }
      g.drawString(sb.toString(),10,50);
    }
  }
}



// Unicode-WingDings at http://www.csn.ul.ie/~caolan/wingdings/proposal/
0
 

Author Comment

by:ddgamer
ID: 7161193
Hmm ... looks like I'll have to experiment since if I use the SansSerif font it works fine. Thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7161729
Thanks. My example works equally well with a serif font actually.
0
 

Author Comment

by:ddgamer
ID: 7162509
Yeah, but when I specify Lucida Sans is when it doesn't work for me for a lot of the characters.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question