Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Combobox Issues  RSS feed

 
Jaime Alnwick
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I know the below code it not very optimized but the main problem I am having is with the combobox when I try to delete the first item. The combobox is set to -1 and I receive an Array Index Out Of Bounds Exception due to this line: selection = songList.get(index). I can change the index to equal 0 if t's -1 but then all items from the combobox are removed for some reason. I have tried several revisions to address this but I cannot seem to figure out how best to approach this, so I was wondering if anyone might have any suggestions. Thanks in advance for any recommendations.

FYI, I have a separate Song class and a separate class that extends JFrame that is not posted.

 
Knute Snortum
Sheriff
Posts: 4070
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The combobox is set to -1 ...

This happen when there is no item selected in the combo box.  After a delete there is no item selected, so select an item (like 0).
 
Rob Camick
Ranch Hand
Posts: 2800
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You question is about a combo box with two values.

Why would you post over 300 lines of code??? We don't have time to look at all that code.

Post a proper SSCCE that demonstrates the problem. That is all you need is a frame and a combo box. The rest is unrelated to your problem.
 
Knute Snortum
Sheriff
Posts: 4070
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you post over 300 lines of code??? We don't have time to look at all that code.

In fairness, we sometimes ask an OP to post more code to give us context, but I agree that a SSCCE would be good in this situation.
 
Rob Camick
Ranch Hand
Posts: 2800
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we sometimes ask an OP to post more code to give us context


I never do. I always ask for a proper SSCCE. The idea is to learn how to do the basic functionality using simple code. Once you prove the basic concept works you then see how your real application is working.

I am never interested in seeing a core dump of the application. The whole point of the SSCCE is to minimize the code by isolating the area causing the problem.

 
Jaime Alnwick
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize for posting all that code. For some reason I thought more was better. In the future, I will stick with a SSCCE. I realize it was unnecessary, especially since the issue was resolved pretty simply as shown below. Not sure why I was struggling with it so much. If a moderator would like to edit the post, please feel free. Again, sorry and thanks for the tip.

   if (songList.size() > 0)
    {
      selection = songList.get(index);
    }
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!