Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

reset caret position to begining of Jtextpane  RSS feed

 
yasir IT2k
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Iam using a JTextPane surrounded with Jscrollpane in a JFrame.On press of enter key, i need
to capture the typed text in the JTextPane,clear it and reposition
the cursor to the start of the JTextPane.However, the cursor is
going to the second line.could anybody tell me why and how do i
position it to the top.
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe there is still a newline left in the text pane after you removed the text?! how do you position the caret after the removal?
c
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"yasir IT2k" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

Thanks! and welcome to the JavaRanch!
 
keerthi matta
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I think for ur requirement setCaretPosition(0) will solve the problem , capture the Enter Key event and explicitly setCaretPosition(0)
Hope this solves ur problem
njoy coding
keerthi
 
dien nguyen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friend,i got the same problem like you,i try to search google but nothing's helpful.Fortunately my friend told me the solution.When you listen to the key event,put the consume() statement in your code,so that the jtextpane will not make a newline when your press enter
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!