aspose file tools *
The moose likes Swing / AWT / SWT and the fly likes JTextPane default font Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextPane default font" Watch "JTextPane default font" New topic
Author

JTextPane default font

Shane Roylance
Ranch Hand

Joined: Aug 29, 2001
Posts: 72
Here is a program I got from the java tutorial on using JTextPane, modified to make it simpler and to show my problem. If you compile this code and run it a JTextPane will come up with some text. Now go to the end of the text, press enter and type a character or two. Delete the character(s) you just typed, then type another character. What you see is that the font is now different, it turns into what looks like a 12 pt font instead of the 24 pt font that it was. My question is why does it do this, and how can I stop it from doing that?
Thanks in advance
Shane
Shane Roylance
Ranch Hand

Joined: Aug 29, 2001
Posts: 72
Anyone have any input on this? Is there a setting for a default font in JTexPane? Is there such a thing as the "default font"?
It looks like there are tags around the text telling it the style it shoulb be in, somehow we get outside the tags, and it reverts to a different font. Is that what is happening? Do I need to submit a bug to Sun?
Thanks again for any assistance
Shane
Shane Roylance
Ranch Hand

Joined: Aug 29, 2001
Posts: 72
I found the answer. If you place this code before you instantiate the TextPane it will set the default to whatever you want.
Enjoy.
KR Campbell
Ranch Hand

Joined: Mar 26, 2004
Posts: 124
Nice question, Shane!
I hurt my head thinking about it yesterday but it caused me to re-discover the Java Swing book which has a whole section on text. I only got as far as DefaultStyledDocument and the fact that the default settings of StyleConstants determine values for JTextPane because there is an empty default Style which uses these.
How did you find the answer or was it a flash of inspiration?
Regards,
Kenny
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JTextPane default font