Scroll action in java
I am a beggar in java, I have a textarea and I have only set the vertical scrollbar to this file. I add data every 1 minute to the textarea, the problem is when new data is attached to the textarea scrollbar, it will move up. To see new data, every time I have to drag the scrollbar, this is not a requirement. I need the scrollbar not to move up, it should move down, how can I do that? Plz help me.
thanks for the answer
0
ganesh
source
to share
3 answers
Something like this should work:
JTextArea display= new JTextArea();
JScrollPane scroll =new JScrollPane(display);
scroll.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener(){
public void adjustmentValueChanged(AdjustmentEvent e){
JTextArea textArea = (JTextArea)e.getSource();
textArea.setCaretPosition(textArea.getDocument().getLength());
}
});
Thus, it will be fully automated.
+1
source to share