[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

Scrolling a List Component

I have a List component which will hold 20 items.  I fill it by reading a file with 100 lines and making each line an item in the list. Based on a Button click I clear the List, recreate the file and reload the List. I would like to have the List window scrolled down so that a given entry (based on the file content e.g. 30) is at the top of the window. How can I do this?
0
jc31415
Asked:
jc31415
1 Solution
 
msmolyakCommented:
Did you try calling myList.select(30)?
0
 
jc31415Author Commented:
I tried myList.select(30),and it doesn't solve my problem. The displayed entries don't change. I have to use the mouse to scroll to the second page to see the selected entry.
0
 
aziz061097Commented:
Use the method makeVisible(int index) and select(int index).
//Listtest.java
import java.awt.*;

public class Listtest extends Frame {

public static void main(String args[]){

List l1 = new List();
String listx[] = {"0","1","2","3","4","5","6","7","8","9",
                  "10","11","12","13","14","15","16"};

for (int i=0;i<listx.length;i++)
 l1.add(listx[i]);

Listtest f1 = new Listtest();
f1.setLayout(new FlowLayout());
f1.setSize(300,200);
l1.makeVisible(14);
l1.select(14);
f1.add(l1);
f1.setVisible(true);
}
}
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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