开发者

How to change that array of items in JComboBox at runtime

开发者 https://www.devze.com 2023-03-11 22:04 出处:网络
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 con

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

精彩评论

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

关注公众号