• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Arrow key to traverse items in JList  RSS feed

 
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.
 
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.
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!