Solved

Scrolling a List Component

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

734 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