Java jeditorpane html font

System Requirements: Windows 8, Windows 7, Windows 8.1


Joe Vahabzadeh Ranch Hand Posts: 140 posted 7 years ago All, Ok, I've got a bit of a problem, and maybe I'm overlooking something obvious. I need to use a JEditor Pane, as far as I know, to be able to have clickable links in the midst of non-link text. However, JEditor Pane is using a different font than the typical JLabel font when I do this. How do I get the text (including the a href links) in the JEditor Pane to use the same font as a typical, non- HTML JLabel would use? Thanks in advance. Joe Vahabzadeh Ranch Hand Posts: 140 posted 7 years ago Hey - well, it took DAYS of searching, but finally found something buried on the internet that explains how to do this. So, if anyone else ever runs into this problem, take a look at the article: Make JEditor Pane use the system font.
Michael Finney Ranch Hand Posts: 508 posted 13 years ago Taken from Chris Smith's excellent post in comp.lang.java.gui ( I want to know the answer too.) The following code attempts to allow the user to enter text, set its font size to vey large, and then save it. It appears to work, except the HTML it writes looks like this: Some Text when I would expect it to look like either this: Some Text or this: Some Text If I change the add CSSAttribute call to read as follows: doc.get Style Sheet.add CSSAttribute(attr, CSS. Attribute. FONT_ SIZE, 7 then it writes the HTML that I want (the first form but the current view of that HTML uses a 7-point font rather than the HTML font size index of 7 (and that's a huge difference). If I close and reopen the document, then it shows correctly using a large font for the text. It appears that I can get either correct behavior of the view *or* write out correct HTML from the Editor Kit write method, but not both. Unfortunately, both are business requirements, and I'm hoping I won't have to start inserting Font elements and setting their attributes by hand. Incidentally, the problem is being reproduced here using the 1.4 release. I haven't had the chance to test on earlier JDK versions. Thanks a bunch! Chris Smith Code: = import java.awt. import java.awt.event. import javax.swing. import javax.swing.text. import javax.swing.text.html. import java.io. public class Editor Test extends JFrame private JEditor Pane pane; public Editor Test JButton save Button = new JButton( Save save Button.add Action Listener(new Action Listener public void action Performed( Action Event event) save JButton big Button = new JButton( Make It Big! big Button.add Action Listener(new Action Listener public.