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?
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.
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?
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.
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.
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 ""})
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 "");
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.