JComboBox to indicate age

Purpose: JComboBox to list the ages that the user can select

I understand that I need an array of integers. What part of the Math functions in Java will allow me to do this easily? The list of numbers will be from 1 to 100 in sequential order.

+1
source share
4 answers

I don’t quite understand why you need math functions.

This will work:

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

You do not need math functions. Take a look at JComboBox in java docs and you will find the .addItem function. It can take a string (for example, "1") or a number (for example, a new integer (1)). Just go to the for loop and add the elements you need.

+3
source

I suspect JSpinner using SpinnerNumberModel will be the best component for choosing integer age or YOB. For more details, see How to use Spinners in the tutorial.

3 spinners

+2
source
+1
source

All Articles