aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Updating JComboBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Updating JComboBox" Watch "Updating JComboBox" New topic
Author

Updating JComboBox

Kevin Magee
Greenhorn

Joined: Feb 02, 2002
Posts: 18
Hi,
This is my first time using Swing, and I've having
a major problem with JComboBox.
My problem is, after populating the ComboBox using
a Vector and the toArray() method. I'm having trouble updating the ComboBox when items have
been added, amended or deleted in the Vector.
Here is some of my code

Now, I can change the Vector easily enough using
the getSelectedIndex() method with ComboBox, and using the result to select Vector elements, but
I cant get the ComboBox to update. I've tried to use the index position to delete and add items, but that doesn't and really I'm now at a loss
Any help would be greatly appreciated.
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
This is an update of the example I gave you before. There are other ways to do this as well. This just shows you the concept.
Kevin Magee
Greenhorn

Joined: Feb 02, 2002
Posts: 18
public void removeComboBoxItem(int a){
textChoice.removeItemAt(a);
}
Thanks for the help
In order for the ComboBox to display
readable text I've created a seperate Vector
called ListName, containing only the Surname from
each record. This Vector is fed to the JComboBox
via its toArray() method.
I've tried to update the ComboBox using the following method

The called method is


Which removes the corrosponding entries from the two Vectors. However, I get a nullPointerException
when I call the two methods to remove the items from the ComboBox.
These methods are

Since, the index position has been passed straight through and back without changing, I don't understand the nullPointer exception.
Or am I just being really stupid???

Never mind, I was just being very, very stupid!!! :roll:
[ February 07, 2002: Message edited by: Kevin Magee ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Updating JComboBox
 
Similar Threads
JComboBox popup refresh in a JApplet
JComboBox (again!!)
how to set the "background selection color" of a Combobox
ComboBox Item Display
JTable +JComboBox