• Post Reply Bookmark Topic Watch Topic
  • New Topic

JList - get next item?  RSS feed

 
kelly bones
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have populated a JList from a DefaultListModel. When an item in JList is selected it plays an MP3 file which can fire an event to signal the MP3 track has ended.

Is there an index I can increment in JList or do I have to go back to the DefaultListModel and then find the appropriate JList entry to play the next track automatically please?

kelly
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not quite clear with your requirment. As far as I understand, you can use jList.setsetSelectedIndex(jList.getSelectedIndex() + 1) to increment your JList selected item... But your application need to listen to the "end of song" event and check appropriate index bound so that it stops when it reaches the last index in the list...

But if you can provide your code here, we might be able to help you more... But we, the Ranch, definitely discourage spoon-feeding... We will give you tips and you might need to figure out the way to solve the problems by yourself...
 
kelly bones
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi yes I don't want a given answer it's jsut I may be missin a simple option her and getting a bit confised with types.

I have tried to navigate about my JList using SelectedIndex / SelectedValue (get & set) but run into a few problems with the types clashing (index needing int and value being the file path & name object).

my code runs but htis latest development is proving a bit tricky:



when I try to call the next track



doesn't work

This is very 'bitty' but it is a long code listing to post it all

any advice where to look next will be much appreciated

love

kelly
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if the current list index is trackNo
this line in the if(cmd.equals("Next")) block

list.setSelectedIndex(trackNo--);

will not change the index.
perhaps it should be --trackNo (even ++trackNo if it is supposed to be 'next')
but you will need to build in a way to return to index 0, something like

list.setSelectedIndex(++trackNo % listModel.size());
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn's suggestion is right... You need to increment or decrement first before the list.setSelectedIndex() method... Or you can use like this as well...


Above code will work the same way as the way that Michael Dunn suggested above...

Hope this helps...
 
kelly bones
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
many thanks for you help - the [trackNo--] was my typo! typical!

love

kelly
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!