JComboBox to list age

雨燕双飞 提交于 2019-11-28 02:22:27
Adel Boutros

I don't quite understand why you need the Math functions.

This would work:

List<Integer> age = new ArrayList<Integer>();
for (int i = 1; i <= 100; ++i) {
    age.add(i);
}
JComboBox ageComboBox = new JComboBox(age.toArray());

You don't need any math functions. Look up JComboBox in the java docs and you'll find a .addItem function. It can take a String (e.g. "1") or a Number (e.g. new Integer(1)). Just iterate in a for-loop and add the items you need.

I suspect a JSpinner using a SpinnerNumberModel would be a better component for selecting an integer based age or Y.O.B. See How to Use Spinners in the tutorial for more info.

mKorbel

maybe you have look at AutoComplete ComboBox / JTextField

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!