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 6 of 6

Thread: Font Size

  1. #1
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Font Size

    I am trying to change the Font size of a JEditorPane by using following method

     
    setFont(new Font("Verdana", Font.PLAIN, 10));

    but it the font doesn't change. Is there anything else that I should set up?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Font Size

    More info is needed. Based upon your other posts if you are setting the content type of the JEditorPane to html, I don't think the change in font makes a different and any changes should be specified in the html itself.

  3. #3
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: Font Size

    yes the content is html. the problem is that when the file is displayed by web browser the font size is normal but when it is shown in the JEditorPane the words become larger. I want to force JEditorPane to keep the original fone size.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Font Size

    You could try altering the default font the JEditorPane uses by setting the font via css
     ((HTMLDocument)editorPane.getDocument()).getStyleSheet().addRule(""+
    "body{"+
    "font-family:Arial;"+//whatever font you want
    "font-size:12px;"+//font size
    ""})

  5. #5
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: Font Size

    what you have sent has some errors I test the following code but it doesn't do any thing.

    HTMLEditorKit Hkit = new HTMLEditorKit();
          editorpane.setEditorKit(Hkit);
            StyleSheet HstyleSheet = Hkit.getStyleSheet();
            HstyleSheet.addRule(""+
            		"body{"+
            		"font-family:Arial;"+//whatever font you want
            		"font-size:4px;"+//font size
            		"");

  6. #6
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Font Size

    Hopefully this link will help you:

    http://www.javaprogrammingforums.com...ize-color.html
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. 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
  2. Change font color and size
    By javanovice in forum AWT / Java Swing
    Replies: 2
    Last Post: April 20th, 2010, 09:57 AM
  3. Checkbox - Change Font Color
    By wakebrdr77 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 10th, 2010, 10:57 AM
  4. [SOLVED] Hashtable and Key Size
    By sapzero in forum Collections and Generics
    Replies: 0
    Last Post: January 28th, 2010, 02:31 PM
  5. Need help with setting multiple font styles in jTextPane
    By jch02140 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 23rd, 2010, 06:16 AM