Skip to main content

JTextPane font size issue

7 replies [Last post]
branded_rhombus
Offline
Joined: 2009-02-18

Hi

I am creating a basic HTML editor using JTextPane. The issue which I am having is that when I set a font (eg Arial 12), it displays much smaller than Arial 12 does in any other editor. I have tried setting the W3C_LENGTH_UNITS and HONOR_DISPLAY_PROPERTIES client properties, and this seems to work only some of the time. Does the W3C_LENGTH_UNITS property need to be set every time I refresh the Document? Or is there something else which I am missing?

Thanks

Mark

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dradud
Offline
Joined: 2012-03-11

I have the same problem, i`m doing a text editor and i change font size style , bold italic , same problem with size, it doesn`t affect me mutch, but the bold and italic are all over the place, I spent a day checking my code for errors , to resolve the bold italic issue. I gave up and now i`m looking for the solution on the net.

dma02
Offline
Joined: 2006-06-20
branded_rhombus
Offline
Joined: 2009-02-18

Thanks for the link. I have checked through it, and am not doing anything differently (as far as fonts and sizes are concerned).

Is there anything else I can do to force the size to be correct (and consistent?)

Thanks!

johnpm
Offline
Joined: 2005-06-15

You may be experiencing a similar problem to one that occurs with JEditorPane, try this link: http://explodingpixels.wordpress.com/2008/10/28/make-jeditorpane-use-the...

branded_rhombus
Offline
Joined: 2009-02-18

Thanks for the link, but I am already doing that. The problem is when I select some text and set the font - I can see that the underlying HTML is correct, but the JTextPane is rendering the font too small (but in some cases it works - I haven't worked out yet what causes it to break).

Any other ideas?

Thanks!

johnpm
Offline
Joined: 2005-06-15

I guess it may help to see the underlying HTML generated when you change the font, are you specifying the font size in an associated STLYE tag?

branded_rhombus
Offline
Joined: 2009-02-18

Below is the underlying HTML. I have tried altering the size mappings in StyleSheet using the function getStyleSheet().addRule("BASE_SIZE 18"); - this worked for all cases except on a new line (when a new leaf node is created, StyleSheet calls css.styleConstantsValueToCSSValue((StyleConstants) key, value); - and this always uses the default size map, not a user assigned one. And it is a package private method :-(

So, I am out of ideas. Its so frustrating that I can't fix the issue above because nearly everything in StyleSheet and CSS is package private.

Also - I get my size mappings for point sizes to HTML sizes from StyleSheet (1 based):
static final int sizeMapDefault[] = { 8, 10, 12, 14, 18, 24, 36 };
This is what I populate the combo box of font sizes with, and what the 7 HTML sizes need to look like on screen.




<*p style="margin-top: 0">
<*font face="Times New Roman" size="3" color="#000000">hello world
<*/p>