Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextPane default font

 
Shane Roylance
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic