File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Font sizes in a JTextPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Font sizes in a JTextPane" Watch "Font sizes in a JTextPane" New topic

Font sizes in a JTextPane

Joe Crew
Ranch Hand

Joined: Apr 02, 2001
Posts: 49
I have a question which I hope won't be too difficult. I have created both a swing application that is a text editor. The user can cut, copy, and paste text. The user can also change the "font style" and "font size" through a series of combo boxes. When the application is launched there are 2 user inputs which indicate the size of the JTextPane area. For example, the user would type in: >java texteditor 2.5 3.0
and the editor launches with a JTEXTPANE width of 2.5 inches and height of 3.0 inches. This is to be a WYSIWYG type editor which will eventually print what is contained in the text area.
Finally my question. When the user decides to change the font size, I have noticed that the font size does not appear to be the correct size as compared to a MS Word Font Size. For example, type a phrase in MS Word and set the font size to be 12, and I type the same phrase in my JTextPane to be 12, the text in the JTextPane is much smaller. I actually have to set the font size to be 16 in the JTextPane to match the MS Word Font size. I have used many differnt fonts and in every single case the in JTextPane I have to add 4 to the font size to make it match the font size of the same phrase in MS Word. Does anyone have any idea what is going on here? Does Java (I am using JDK118, it's REQUIRED on my part) have it's own font rendering engine that is differnt that what I see in MS Word? Why would 2 fonts, 1 in MS Word and another in a JTextPane, appear differntly. The JTextPane is always 4 too small. I can compenstate for this by adding 4 but that does not tell me why it is happening.
Joe Crew
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Font sizes in a JTextPane
It's not a secret anymore!