This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Arrow key to traverse items in JList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Arrow key to traverse items in JList" Watch "Arrow key to traverse items in JList" New topic
Author

Arrow key to traverse items in JList

Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Hello friends

I am using a JList. I traverse the items in JList using arrow keys. When the selection is on the last item of the list and upon subsequent pressing of down arrow key the selection should change to first item in list. And as such traversal should go on infinitely untill the down arrow key is pressed.

The reversal is applicable for the up arrow button.

To do this I implemented KeyListener but then in keyPressed I am unable to move the focus on the first element of the JList.

Can anyone please help me in this regards ?

Waiting for your replies..

Thanks and Regards
Rohit.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
this works OK (list is the JList, dlm is the DefaultListModel)
(reverse it for the up arrow)

Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Originally posted by Michael Dunn:
this works OK (list is the JList, dlm is the DefaultListModel)
(reverse it for the up arrow)



Thanks Michael
I will try it out and will let you know...Hope it works for me.

Thanks for the reply.
Rohit.
Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Hey Michael

That did worked.. Thanks a million man..
Thanks for your help

Regards
Rohit.
[ January 06, 2006: Message edited by: Rohit Bhagwat ]
Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Hi Michael

Now I want to do the same thing for a group of radio button.

I tried to do the same thing but it didnt worked.

What I did is

if(getFocusOwner() instanceof JRadioButton)
{
if(ke.getKeyCode() == KeyEvent.VK_DOWN && mLastRadioButton.isSelected)
{
ke.consume();
mGroupsRadioButton.setSelected(true);
}
}

Can you please help me in this regards

Waiting for your reply.

Thanks
Rohit.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
something to play around with

Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Thanks a lot..Michael

Thanks and Regards
Rohit.
 
jQuery in Action, 2nd edition
 
subject: Arrow key to traverse items in JList
 
Similar Threads
Disabling Keybinding For Particular Component
keycode capturing not working
KeyBoard events not listening in JPopupMenu
problem selecting JList item
key pressed in JList and selecting the item based on that