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

Help with JComboBox  RSS feed

 
Cathy Young
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am creating a JComboBox using the constructor:

The elements to be displayed in Vector v may be changed, so whenever the Vector changes, the items to be displayed on the JComboBox need to change accordingly.
I am doing something like this:

But by this way, the elements are not updated correctly. What should I do?
Thanks,
--Cathy
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stop manipulating the Vector after you use it to construct the combo box. Instead of:
v.removeAllElements();
use:
combo.removeAllItems();
 
Cathy Young
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Greg Charles:
Stop manipulating the Vector after you use it to construct the combo box. Instead of:
v.removeAllElements();
use:
combo.removeAllItems();

Thanks, Greg. But the vector is changing and the items to be added to the JComboBox are exactly the items in Vector.
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
do

for a more custom behaviour you should implement your own MutableComboBoxModel, or extend the default one. you can do the updating inside the model. it is meant for it.
chantal
 
Cathy Young
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chantal Ackermann:
hi,
do

for a more custom behaviour you should implement your own MutableComboBoxModel, or extend the default one. you can do the updating inside the model. it is meant for it.
chantal

Thanks, Chantal, that helps!
--Cathy
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!