Forums Register Login

Arrow key to traverse items in JList

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
this works OK (list is the JList, dlm is the DefaultListModel)
(reverse it for the up arrow)

+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
Hey Michael

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

Regards
Rohit.
[ January 06, 2006: Message edited by: Rohit Bhagwat ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
something to play around with

+Pie Number of slices to send: Send
Thanks a lot..Michael

Thanks and Regards
Rohit.
Do you want ants? Because that's how you get ants. And a tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 5358 times.
Similar Threads
Disabling Keybinding For Particular Component
key pressed in JList and selecting the item based on that
problem selecting JList item
keycode capturing not working
KeyBoard events not listening in JPopupMenu
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:27:24.