This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Formatted text pane problem  RSS feed

 
Lukas Benberg
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey all,
can somebody help me out with this? i have a JTextPane formatted with a StyledDocument. characters 6-9 of the text are highlighted. after i change parts of the text, the highlight expands over the whole text. how can i make the highlight stay correct (namely at chars 6-9).

thank you!

 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the JTextPane api scroll down to the section "Methods inherited from class javax.swing.JEditorPane" and find the setText method. Follow the link to the Method Detail section of the JEditorPane api. Using this method replaces all content in the StyledDocument. To allow the attributes to remain in the document use the Document method insertString.
 
Lukas Benberg
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank! that was very helpful!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!