Re: Trying to get JComboBox to "repopulate" with increased java.util.Vector
phillip.s.powell@gmail.com wrote:
On Feb 9, 11:27 am, Nigel Wade <n...@ion.le.ac.uk> wrote:
If you remove/add components I think you need to revalidate().
Do you really need to keep creating, adding and removing components? Is there
a
reason that you can't just change what the existing components are
displaying?
At this point I believe that changing components is both overhanded
and misleading, while changing models have no effect whatsoever. Is
there a way to change the way JComboBox LOOKS in relation to an
increased Vector?
If changing the models has no effect then you must not be doing it correctly.
Are you actually creating a new model and changing the model for the JComboBox,
or just changing the contents of the existing model? If by LOOKS you mean
change the JComboBox contents and have those new contents display in the GUI,
then of course that's possible.
The simplest way to do this is using the DefaultComboBoxModel/JComboBox methods
removeElement(), removeAllElements(), insertElement()/removeItem(),
removeAllItems(), addItem() etc.
For example, this code is from a client I have which looks up UNIX credentials
in an LDAP directory and displays the results. This particular section shows
all the valid Group names in the combo box groupNameCombo:
ArrayList<Group> groups = server.getGroups();
groupNameCombo.removeAllItems();
for(Group group:groups) {
groupNameCombo.addItem(group);
}
What Group actually is doesn't concern JComboBox, it just displays the result of
its toString() method. This code must be executed within the EDT.
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555