• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Make List Scroll to latest added item

public class udpClient extends Applet {
      Label lblCommon =  new Label("Text Here");
      Panel pTop = new Panel();
      Button bEnter = new Button("Enter");
      TextField txtChat      = new TextField(20);
      List lst = new List(4, false);
      
      public void init() {
          
            class BL implements ActionListener {
                  public void actionPerformed(ActionEvent e){
                        lst.add(txtChat.getText());
                        lst.add(Integer.toString(lst.getItemCount()));
                        lst.select(lst.getItemCount());
                        lst.makeVisible(lst.getItemCount());
                         
                  }
            }
            
            BL a = new BL();
            bEnter.addActionListener(a);
            
            resize(320,400);
            
          setLayout(new BorderLayout());
          add(pTop,BorderLayout.NORTH) ;
                
                pTop.add(lblCommon);
                pTop.add(txtChat);
                pTop.add(bEnter);
          
          add(lst,  BorderLayout.CENTER);
                  
    }
}

heres my simple example.. somehow i cantt make the list box scroll to the most recent added item... there were no errors reported on my coding..
 
thanks.
0
load_o_crap
Asked:
load_o_crap
  • 2
1 Solution
 
heyhey_Commented:
try
lst.makeVisible(lst.getItemCount() - 1);
0
 
heyhey_Commented:
.. and delete the other question ...
0
 
vivexpCommented:
Hi,
I used the select method in the class List.

use   li.select (li.countItems()-1);
or
li.select (li.getItemCount ()-1);

to select the last item added.

Best of Luck
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now