JComboBox to list age

后端 未结 4 1144
旧时难觅i
旧时难觅i 2020-12-07 05:12

Purpose: JComboBox to list down ages that a user can select

I realize that I need an array of integers. What part of the Math functions in Java will allow me to easi

相关标签:
4条回答
  • 2020-12-07 05:55

    maybe you have look at AutoComplete ComboBox / JTextField

    0 讨论(0)
  • 2020-12-07 05:59

    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.

    3 spinners

    0 讨论(0)
  • 2020-12-07 06:09

    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.

    0 讨论(0)
  • 2020-12-07 06:14

    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());
    
    0 讨论(0)
提交回复
热议问题