JEditorPane always scrolls down to the bottom, how can I prevent this?

Hello, I have the following code that contains a JTable and JEditorPane in a panel. When I click on a headline on the table, I have some text showing up in the lower pane. My problem is that the lower pane (that is inside a JScrollPane) always scrolls down to the end of the text, but I want to to always point to the beginning.
Does anyone know how to do this?
Your help will be appreciated.
Thanks!
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Point;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JViewport;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
public class MyHTMLPaneTest {
     JFrame frame;
     JPanel panel;
     JSplitPane splitPane;
     JTable table;
     JEditorPane htmlPane;
     JPanel tablePanel;
     DefaultTableModel model;
     JViewport viewPort;
     public MyHTMLPaneTest()
          frame = new JFrame("MyCalHTMLPane Test");
          panel = new JPanel(new BorderLayout());
          splitPane = new JSplitPane();
          tablePanel = new JPanel(new BorderLayout());
          setTable();
          tablePanel.add(table.getTableHeader(), BorderLayout.NORTH);
          tablePanel.add(table, BorderLayout.CENTER);
          htmlPane = new HTMLPane();
          JScrollPane pane = new JScrollPane(htmlPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
          viewPort = pane.getViewport();
          viewPort.setViewPosition(new Point(0, 0));
          splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tablePanel, pane);
        panel.add(splitPane, BorderLayout.CENTER);
          frame.getContentPane().add(panel);
          frame.setSize(new Dimension(400, 300));
          frame.setVisible(true);
     public void setTable()
          String[] columnNames = {"Date","Time","Subject"};
         Object[][] data =
              {"03/31/05", "8:20 AM EDT", "Headline 1"},
              {"08/24/05", "8:19 AM EDT", "Headline 2"},
              {"08/18/05", "8:18 AM EDT", "Headline 3"},
             {"08/12/05", "8:17 AM EDT", "Headline 4"},
             {"06/20/05", "8:16 AM EDT", "Headline 5"},
             {"06/20/05", "8:15 AM EDT", "Headline 6"}
         model = new DefaultTableModel(data, columnNames);
         table = new JTable(model);
         table.getSelectionModel().addListSelectionListener(new ListSelectionListener()
             public void valueChanged(ListSelectionEvent e)
                  String text = "LOOOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOOOOOOOOOONG" +
                            "\nLOOOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOONG"+
                            "\nLOOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG"+
                            "\nSTRIIIIIIIIIIIIIIIII" +
                            "\nIIIIIIIIIIIIIIIIIIII" +
                            "\nIIIIIIIIIIIIIIIIIIIII" +
                            "\nIIIIIIIIIIIIIIIIIIIII" +
                            "\nIIIIIIIIIIIIIIIIIIIIING"+
                            "LOOOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOOOOOOOOOONG" +
                            "\nLOOOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOONG"+
                            "\nLOOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOOOO" +
                            "\nOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG"+
                            "\nSTRIIIIIIIIIIIIIIIII" +
                            "\nIIIIIIIIIIIIIIIIIIII" +
                            "\nIIIIIIIIIIIIIIIIIIIII" +
                            "\nIIIIIIIIIIIIIIIIIIIII" +
                            "\nIIIIIIIIIIIIIIIIIIIIING";
                  htmlPane.setText(text);
     public static void main(String[] args) {
          MyHTMLPaneTest test = new MyHTMLPaneTest();
}

try setCaretPosition:
        table.getSelectionModel().addListSelectionListener(
                new ListSelectionListener()
                    public void valueChanged(ListSelectionEvent e)
                        String text = "LOOOOOOOOOOOOOOOOOOO"
                                + "\nOOOOOOOOOOOO"
                                + "\nOOOOOOOOOOOOOOOO"
                                + "\nOOOOOOOOOOOOOOOO"
                                + "\nIIIIIIIIIIIIIIIIIIIII"
                                + "\nIIIIIIIIIIIIIIIIIIIIING";
                        htmlPane.setText(text);
                        htmlPane.setCaretPosition(0);  // ******* here **********
                });

Similar Messages

Maybe you are looking for

  • Problem while installing adobe photoshop cs6

    Hey guys, I have been trying to install adobe photshop CS3 trial version on my MAC. I have the adobe air installed. When I get to adobes webpage to download the trial version i get this message: This application cannot be installed because this insta

  • Activating screen says I'm not connected with internet

    Acrobat 10 stopped working - found a solution calling for deactivating CS6 and re-activating. Deactivated fine but when reentering the serial number and then activate.... screen states I am not connected to the internet (and I am). Have tried several

  • Premiere crash down when trying to export Prores - on a mac!

    Hi, I have a Mac Book Pro, mid 2010, with Lion, and a new SSD drive. I managed to export 18mn in Apple Prores 422HQ, like the original footage, 2 days ago from Premiere Pro CC 2014. It took a while, around 3 hours, but it worked. Today, when I try to

  • Using Add-SQLAvailabilityDatabase command

    Hi All, I'm trying to get the Add-SqlAvailabilityDatabase command working. This is how the command is supposed to be formatted: Add-SqlAvailabilityDatabase -Path "SQLSERVER:\SQL\PrimaryServer\InstanceName\AvailabilityGroups\MyAg" -Database "MyDatabas

  • Export failed, archive corrupt error

    Hi - I am getting an Export failed, archive may be corrupt error when I try to export my EAR from Workshop 9.2 MP1. (Oddly enough, if I build my EAR with the exported Ant scripts, that works. I can deploy and run this EAR). An the EAR is truly corrup