动态更改JComboBox [英] Dynamically change JComboBox

查看:160
本文介绍了动态更改JComboBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从数据库中成功获取数据值。我还将它们存储在 String [] 数组中。我需要加载String数组作为 JComboBox 的项目,以响应执行的关键操作。每当按下一个键时,如何重新加载 JComboBox 的项目,因为获取的值取决于按下的键。相反,我需要动态刷新 JComboBox 项目。

I am fetching the data values from the database successfully. I have also stored them into a String[] array. I need to load the String array as the items of the JComboBox in response to key actionperformed. How can I reload the items of the JComboBox whenever a key is pressed as the fetched values depend on the key pressed. Rather simply, I need to dynamically refresh the JComboBox items.

推荐答案

DefaultComboBoxModel model = new DefaultComboBoxModel( yourStringArray );
comboBox.setModel( model );

这篇关于动态更改JComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆