• Post Reply Bookmark Topic Watch Topic
  • New Topic

changing contents of a combo box

 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone have an example of modifing the contents of a JComboBox on the fly?

Let's say I have a combo box with a list of the numbers from 1 through 10.

Later on I want that same comboBox to have the letters of the alphabet.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can just give you model the new data. However, if going from 1 type of data to another, it may be just as easy to specify a new combobox all together instead of just changing the model.
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe this will help.

Here is a quick and dirty example of my problem.


Basically, my application has a combo box that is not enabled (like this one). After the user presses the button then the application will gather new information that it is supposed to populate the combo box with.

I must be missing something obvious here...
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With a couple of changes to accomodate 'where' the cb is, this seems to work OK

 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, that worked pretty well. Thanks.

Does this solution seem a bit odd to anyone?

This solution works, also a solution where all the elements are deleted and new ones are inserted into the combo box works.

Both of these solutions seem to be "forced" or "naive" (for lack of a better term).

For example, if I wanted to update the contents of a table, I would be able to do that without creating a whole new table.

Is there a similar solution for a combo box?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!