Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Scrolling a List Component

Posted on 1998-06-28
3
Medium Priority
?
181 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

636 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