Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arrow key to traverse items in JList

 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this works OK (list is the JList, dlm is the DefaultListModel)
(reverse it for the up arrow)

 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
something to play around with

 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot..Michael

Thanks and Regards
Rohit.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic