0

I use a JTextpane in a JScrollpane and the contents of the Jtextpane currently displayed are,

Row1
Row2
Row3
Row4

I type CLEAR and on press of ENTER i need to display only the last line scrolling the other lines upwards like below,

Row4

caret at the end of last line(Row4) and while scrolling up the following should be displayed,

Row1
Row2
Row3

Note : I have used keybindings to get enter action and using if condition i get to know that clear is typed.

How can i achieve this please help.

madhu
  • 37
  • 1
  • 10
  • I don't understand your requirement. The Enter key is used to add a new line to the text pane. Are you suggesting you want to change the Action of the Enter key to go to the last line in the Document? What happens in you have 6 lines in the text pane and you are currently showing the first 4 lines and the caret is on line 1 and you press the Enter key? – camickr May 11 '14 at 04:40
  • @camickr i type clear and press enter..also i have coded in a way that my caret will not move above the last line.So at any point of time caret position will be at last line only. Please see my updated question. – madhu May 11 '14 at 04:50
  • `I type CLEAR` - why would you force the user to enter the characters "clear" into the text pane? Should you not have a button called "Clear" that the user can click on to clear the text from the text pane. Sorry, I still don't understand your requirement. – camickr May 11 '14 at 05:05
  • @camickr I am developing something like a terminal tool , so having a clear button is not allowed. It is similar to clear command in LINUX. also by clear i simply cant remove all contents of the Jtextpane but i need to simply hide the contents by scrolling it up programmatically leaving only the last line visible at the top of the Jtextpane.So if user scrolls up manually he will be able to see the contents which was displayed previously. – madhu May 11 '14 at 05:13
  • I understand what you are asking know, but I don't know the answer. A JScrollPane is not designed to function this way. – camickr May 11 '14 at 15:49
  • @camickr Thanks for ur time ! BTW from here [link](http://stackoverflow.com/questions/13165617/how-to-determine-which-lines-are-visible-in-scrollable-jtextarea) I got to know the number of lines currently visible in textpane and am trying to append that much \n ..trying a workaround will see f it works. – madhu May 12 '14 at 03:53

0 Answers0