JScrollPane and JList auto scroll

后端 未结 7 1615
无人共我
无人共我 2020-12-16 14:33

I\'ve got the next code:

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


        
7条回答
  •  爱一瞬间的悲伤
    2020-12-16 15:35

    To auto scroll I am using a very simple concept of static variable and list.makeVisible(int index)

        public class autoScrollExample
        {
         static int index=0;
         private void someFunction()
         /*   
         * 
         */
         list1.add("element1");
         list1.makeVisible(index++);
         /*
         *
         */
    
         private void someOtherFunction()
         /*   
         * 
         */
         list1.add("element2");
         list1.makeVisible(index++);
         /*
         *
         */
    
    
        }
    

提交回复
热议问题