• Post Reply Bookmark Topic Watch Topic
  • New Topic

inserting component in JTextPane

 
kumar mars
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai
I have a problem while inserting components in JTextPane
i first inserted text using insertString() function and then a JLabel using
insertComponent() function but the Label is appearing before the text.
This is the case with any of the component that is being added
The components are being added before the text
can someone tell me a solution by which the components appear in the order they
were added
Thanking you in anticipation
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It says in the JavaDocs that when you call insertComponent() it gets inserted where ever there is text currently selected. If there is no selection, it is inserted at the beginning of the document.

So you have to set the selection to the end of the current text to insert the component in order...

Here's some example code...



-Nate
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!