Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Font Character Selection

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    13
    Thanks
    3
    Thanked 2 Times in 1 Post

    Default Font Character Selection

    Hello, all! I've got a pretty specific goal and I was hoping to get some advice on the best way to achieve it.

    The long and the short of the question is this: How do I detect whether a given character exists in a font that I am using?

    Here are the particulars. I have a program that allows users to select their own font for text display (a core element of the functionality requires this). There are situations when a user will enter text including characters that do not exist in the font. I need a way to make this default the non-displayable characters to a preselected, unicode compatible font that I already have.

    The second element of this will be figuring out how to have the AWT elements know to swap out only certain characters when creating the text, and any suggestions there would be welcome as well.

    Sorry that this issue isn't as straightforward as a block of code, but I'm not quite sure where the best place to start is.

    Any help appreciated!

  2. #2
    Member
    Join Date
    Apr 2014
    Posts
    86
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: Font Character Selection

    Sounds like you need font.canDisplay(char)?

    https://docs.oracle.com/javase/8/doc.../awt/Font.html

    That's the easy part. I would imagine the second part would be quite a challenge. I can't think of any way to do that except for custom drawing of all the text in paintComponent(). Draw some of the string with the user's font, switch to your custom font for a non-displayable character and draw that, then switch back to the user's font, etc. But once you commit to that, then you get to do your own word wrapping, left/center/right alignments, etc.

    I might be overthinking it though, and there just might be something out there I'm not aware of that could make it more simple. But I'm at a loss.
    Last edited by BinaryDigit09; October 20th, 2017 at 07:03 PM.

Similar Threads

  1. [SOLVED] JTextArea font/character count issue
    By psychobeagle12 in forum AWT / Java Swing
    Replies: 7
    Last Post: April 25th, 2012, 06:17 PM
  2. Re: How to Change JTextArea font, font size and color
    By binokyo10 in forum Java Theory & Questions
    Replies: 1
    Last Post: February 5th, 2012, 12:12 PM
  3. How to Change JTextArea font, font size and color
    By Flash in forum Java Swing Tutorials
    Replies: 7
    Last Post: January 14th, 2012, 10:47 PM
  4. The character '' is an invalid XML character exception getting
    By sumanta in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 9th, 2010, 12:13 PM
  5. How to Change JTextArea font, font size and color
    By Flash in forum Java Code Snippets and Tutorials
    Replies: 4
    Last Post: July 8th, 2008, 01:45 PM

Tags for this Thread