Scrolling up the vertical scroll bar

Hi,

Could you tell me please how can I set the vertical scroll bar of a JEditorPane to be at the highest possible point?

Lets say for example that the user clicks on a button and lots of information is printed on a JEditorPane, but the vertical scroll bar is down which means he has to scroll up in order to start reading from the beginning.

Check for example this code:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;

import java.io.*;

publicclass ScrollTestextends JFrame{

JEditorPane jep;

public ScrollTest(){

jep =new JEditorPane();

jep.setEditable(false );

jep.setContentType("text/plain" );

JScrollPane jsp =new JScrollPane();

jsp.setViewportView(jep);

getContentPane().add(new JScrollPane( jep ) );

JButton button2 =new JButton("GO");

button2.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

String str ="INFO INFO INFO";

for(int i = 0; i < 30; i++){

str +="\n";

}

str +="INFO INFO INFO\nEND";

jep.setText(str);

}

});

getContentPane().add(button2, BorderLayout.SOUTH);

}

publicstaticvoid main(String[] args){

JFrame f =new ScrollTest();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setSize(512, 342);

f.show();

}

}

Thank you

[2673 byte] By [Wilagera] at [2007-11-26 21:55:23]
# 1
try jsp.getViewport().setViewPosition(new Point(0, 0))
smalinowa at 2007-7-10 3:51:11 > top of Java-index,Desktop,Core GUI APIs...