Solved

Scrolling a List Component

Posted on 1998-06-28
3
174 Views
Last Modified: 2010-03-30
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
Comment
Question by:jc31415
3 Comments
 
LVL 5

Expert Comment

by:msmolyak
ID: 1224027
Did you try calling myList.select(30)?
0
 

Author Comment

by:jc31415
ID: 1224028
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
 
LVL 2

Accepted Solution

by:
aziz061097 earned 50 total points
ID: 1224029
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now