JScrollPane and JList auto scroll

Posted by dododedodonl on Stack Overflow See other posts from Stack Overflow or by dododedodonl
Published on 2010-01-25T13:11:01Z Indexed on 2010/03/20 17:01 UTC
Read the original article Hit count: 655

Filed under:
|
|
|

Hi All,

I've got the next code:

    listModel = new DefaultListModel();
    listModel.addElement(dateFormat.format(new Date()) + ": Msg1");
    messageList = new JList(listModel);
    messageList.setLayoutOrientation(JList.VERTICAL);

    messageScrollList = new JScrollPane(messageList);
    messageScrollList.setPreferredSize(new Dimension(500, 200));

    messageScrollList.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {  
        public void adjustmentValueChanged(AdjustmentEvent e) {  
            e.getAdjustable().setValue(e.getAdjustable().getMaximum());  
        }
    }); 

It auto scrolls down. But, if I try to scroll back up to re-read a message, it forces a scroll down. How can I fix this?

© Stack Overflow or respective owner

Related posts about java

Related posts about jscrollpane