Populate a JComboBox with an int[]

前端 未结 2 1122
傲寒
傲寒 2021-01-27 16:05

Is it possible to populate a JComboBox with an int[]? I am writing a code that will use a JComboBox populated with years (in integers).

The code I have written is this:

2条回答
  •  没有蜡笔的小新
    2021-01-27 16:59

    JCombobox is generic, but Java generics don't support primitive type (and int is a primitive type).

    So use an Integer array instead :

    Integer[] birthYear = new Integer[currentYear]; //currentYear is an int variable
    int inc=1;
    for(int i=0;i birthYearBox = new JComboBox<>(birthYear);
    

提交回复
热议问题