Solved

Scrolling a List Component

Posted on 1998-06-28
3
175 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

920 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

16 Experts available now in Live!

Get 1:1 Help Now