Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JComboBox (again!!)

 
Kevin Magee
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having a problem updating the ComboBox.
The ComboBox is filled using a Vector containing
a name, the contents of the Vector are cast to Strings, and displayed in the ComboBox.
However, a problem arises when an item is removed
from the Vector list, the ComboBox does not update
Is there an easy way to update this.
The Vector itself is defined in a seperate class.
Thanks for the help,
Kevin
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We really need to see the code that does not work.
 
aymen esawey
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe just call repaint,just a maybe try it.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you are just updating the Vector which you used to create the combo. That does not change the model within the combo. Either change the combo or create your own model and update it.
 
Kevin Magee
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's some of my code.
The first method is called to edit an item in the vector
The second method is in another class (EditCard).
I'm getting the following error
A:\AlumniList.java:89: non-static method updateComboBox(int) cannot be referenced from a static context

 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The syntax ClassName.method() is for calling a static method. If you want to call a non-static method you need to use the syntax
objectName.method();
 
Kevin Magee
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the help!!!

Kevin.
 
Kevin Magee
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hate to be a pain. I just can't seem to get around this whole JComboBox thing (this is my first attempt to use swing).
My problem now is that I'm allowing the user
to select an item from the comboBox, edit, or delete the item. And using the index position from
the comboBox changing the Vector, and then changing the list in the comboBox.
I'm now getting a NullPointerException, when trying to pass the index position to a method which will update the comboBox.

I know the updateComboBox method isnt correct, I need to get the listName.toArray() (since I'm using a Vector in order to display a readable choice), but I just want to get it working, its starting to drive me crazy!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic