Results 1 to 5 of 5
  1. #1
    keo
    keo is offline Member
    Join Date
    May 2010
    Posts
    34
    Rep Power
    0

    Default Special Characters on GUI

    I am having problems with special characters: (♥♣♠♦) (\u2663). I am writing a card game and am converting a system.out game to a GUI game. During system.out, the symbols worked, they also worked on the GUI. But after I tried the below code, it no longer works. I wanted to enlarge the font so I applied the font to the panel. Now even when I comment it out, it doesn't show the symbols anymore. I think it was the middle parameter in Font( , 0, ) that caused this. How do I fix this?.. it just shows squares in place of those symbols.


    Java Code:
    Font newFont = new Font("name", 0, 20);
    panelA.setFont(newFont);
    Last edited by keo; 05-01-2011 at 11:43 AM.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,525
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by keo View Post
    I am having problems with special characters: (♥♣♠♦) (\u2663). I am writing a card game and am converting a system.out game to a GUI game. During system.out, the symbols worked, they also worked on the GUI. But after I tried the below code, it no longer works. I wanted to enlarge the font so I applied the font to the panel. Now even when I comment it out, it doesn't show the symbols anymore. I think it was the middle parameter in Font( , 0, ) that caused this. How do I fix this?.. it just shows squares in place of those symbols.


    Java Code:
    Font newFont = new Font("name", 0, 20);
    panelA.setFont(newFont);
    Don't use those 'magic numbers'; use Font.PLAIN etc. instead. Also be sure that the Font can display your characters, otherwise you'll just see little squares (indicating that the Font can't display the glyphs for that particular character).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    keo
    keo is offline Member
    Join Date
    May 2010
    Posts
    34
    Rep Power
    0

    Default

    Still no luck..I tried using the Font.PLAIN as well as renaming the "name" into all of the font names netbeans is offering me as well as
    Dialog
    SansSerif
    Serif
    Monospaced
    DialogInput...

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You may wish to check which fonts on your system are needed to display your characters, and then use that explicit font rather than one of the Java Logical fonts. If you do this, and your application is distributed to others, you had better check to see if the font you need is available on the user's system. I think that this can be done using one of the static methods from the GraphicsEnvironment class.

    Myself though if I were doing this type of application, I'd download one of the playing card image sets available for free and use actual card images for my game. Why futz around with fonts when you can display the real thing? For a download, please check here: Free PNG Playing Card Images
    Last edited by Fubarable; 05-01-2011 at 09:19 PM.

  5. #5
    keo
    keo is offline Member
    Join Date
    May 2010
    Posts
    34
    Rep Power
    0

    Default

    Thanks for the suggestion. I don't think it'll be the simplest solution as I need to write some of these characters outside of just the cards that are displayed.

    I found out that those special characters belong to Arial only, so why doesn't the code below work when applied to the panel that the label is on?

    The annoying this about this is that it originally worked, and when I wrote some code and removed it, it stopped working =[ If I can't solve this, I'll see if im allowed to do it through the IDE

    Font newFont = new Font("Arial", Font.PLAIN, 20);
    panelA.setFont(newFont);

    Thanks everyone.


    EDIT: Actually I think your right Fubarable, I'll have fun designing my own deck of cards as images rather than solve this boring error! Thanks for that site too!
    Last edited by keo; 05-02-2011 at 03:22 AM.

Similar Threads

  1. Special characters question
    By alexalex1234 in forum Advanced Java
    Replies: 1
    Last Post: 03-24-2011, 11:33 AM
  2. Help - special characters producing 404 errors
    By Knedlikova in forum New To Java
    Replies: 3
    Last Post: 11-17-2010, 09:13 AM
  3. XML with special characters
    By Kaizah in forum XML
    Replies: 1
    Last Post: 11-06-2009, 02:26 PM
  4. How to index the special characters in Lucene
    By talktoudaykumar in forum Lucene
    Replies: 2
    Last Post: 04-23-2009, 07:51 AM
  5. special characters
    By ravian in forum New To Java
    Replies: 2
    Last Post: 11-16-2007, 01:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •