selection in JList
Hi all,
I had some problem in the selection of Jlist while navigating through JList using charecters.
Problem :-
JList is added to a scroll pane.
There are some 100 records in the JList, Now after selecting the first record i keep on pressing some charecter say some 'k'.Now the focus has to move to the record which starts with 'k' by default this can be achived but my scroll bar also should move to the location where the selection is made.
Can any one please help me to sort out problem.
Thanks in Advance,
vamsy.
[577 byte] By [
vamsyva] at [2007-10-3 3:21:30]

HI Michael,
I just created a JList and added to the scroll pane as follows-
kParameterIDsp = new JScrollPane();
kParameterID = new JList();
kParameterIDsp.getViewport().add(kParameterID, null);
The scrollpane size is adjusted such that only 5 rows are visble in the Jlist.
Then i had populated the data into JList as follows-
Vector add = new Vector();
kParameterID.setListData(add);
As you asked 10 elements are as follows which were populated into the Vector add in above code-
Apple
Basket
cat
dog
elephant
Hen
Holland
Hawk
whale
zebra
After populating the above elements into the JList i could view till 5 element elephant above as i had a scroll bar i can drag and view the others.
But the my problem is when i press letter H the focus has to move to Hen so that the scrollBar must also movedown to 6 the element.
works OK in this
import javax.swing.*;
import java.awt.*;
import java.util.*;
class Testing extends JFrame
{
JList list = new JList();
JScrollPane sp = new JScrollPane(list);
public Testing()
{
setLocation(400,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
list.setVisibleRowCount(5);
list.setListData(new Vector<String>(Arrays.asList(new String[]{
"Apple","Basket","cat","dog","elephant","Hen","Holland","Hawk","whale","zebra"})));
getContentPane().add(sp);
pack();
}
public static void main(String[] args){new Testing().setVisible(true);}
}