开发者

How to change that array of items in JComboBox at runtime

I ad开发者_如何学运维d a JComboBox to a JPanel (in the JComboBox constructor I load array of strings). How can I change that array at runtime, to load new items?


Rather than pass your values in the constructor, you should create a ComboBoxModel derived class and pass that to the constructor. A simple example would be DefaultComboBoxModel, but you could create your own if that didn't satisfy your needs. Then you can modify the model and the changes are applied to the ComboBox.


If you want to add new items in JComboBox at runtime then use addItem() method of JComboBox.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜