This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes JComboBox (again!!) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JComboBox (again!!)" Watch "JComboBox (again!!)" New topic
Author

JComboBox (again!!)

Kevin Magee
Greenhorn

Joined: Feb 02, 2002
Posts: 18
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

Joined: Sep 29, 2000
Posts: 8521
We really need to see the code that does not work.
aymen esawey
Ranch Hand

Joined: Jan 29, 2002
Posts: 61
maybe just call repaint,just a maybe try it.


Aymen Esawey<br />SCJP <img src="smile.gif" border="0"> <br /><a href="http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=32&t=001968" target="_blank" rel="nofollow">how to nuke the SUN </a>
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
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

Joined: Feb 02, 2002
Posts: 18
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

Joined: Sep 29, 2000
Posts: 8521
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

Joined: Feb 02, 2002
Posts: 18
Thanks a lot for the help!!!

Kevin.
Kevin Magee
Greenhorn

Joined: Feb 02, 2002
Posts: 18
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!!!
 
GeeCON Prague 2014
 
subject: JComboBox (again!!)