Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用int[]填充JComboBox_Java_Arrays_Swing_Int_Jcombobox - Fatal编程技术网

Java 使用int[]填充JComboBox

Java 使用int[]填充JComboBox,java,arrays,swing,int,jcombobox,Java,Arrays,Swing,Int,Jcombobox,是否可以使用int[]填充JComboBox?我正在编写一个代码,它将使用一个填充了年(整数)的JComboBox 我编写的代码如下: int[] birthYear = new int[currentYear]; //currentYear is an int variable int inc=1; for(int i=0;i<currentYear;i++) { birthYear[i]= inc; inc++; } birthYearBox = new JCombo

是否可以使用int[]填充JComboBox?我正在编写一个代码,它将使用一个填充了年(整数)的JComboBox

我编写的代码如下:

int[] birthYear = new int[currentYear]; //currentYear is an int variable
int inc=1;
for(int i=0;i<currentYear;i++)
{
    birthYear[i]= inc;
    inc++;
}

birthYearBox = new JComboBox(birthYear); //this is the line in which the error occurs
int[]生日=新int[当前年份]//currentYear是一个整型变量
int inc=1;

for(int i=0;i
JCombobox
是泛型的,但是Java泛型不支持基元类型(并且
int
是基元类型)

因此,请改用
整数
数组:

Integer[] birthYear = new Integer[currentYear]; //currentYear is an int variable
int inc=1;
for(int i=0;i<currentYear;i++){
    birthYear[i]= inc;
    inc++;
}
JComboBox<Integer> birthYearBox = new JComboBox<>(birthYear);
Integer[]birthYear=新整数[currentYear];//currentYear是一个int变量
int inc=1;

for(int i=0;i
JCombobox
是泛型的,但是Java泛型不支持基元类型(并且
int
是基元类型)

因此,请改用
整数
数组:

Integer[] birthYear = new Integer[currentYear]; //currentYear is an int variable
int inc=1;
for(int i=0;i<currentYear;i++){
    birthYear[i]= inc;
    inc++;
}
JComboBox<Integer> birthYearBox = new JComboBox<>(birthYear);
Integer[]birthYear=新整数[currentYear];//currentYear是一个int变量
int inc=1;

对于(int i=0;i如果您只想处理整数,可以选择一种方法:

JComboBox<Integer> comboBox = new JComboBox<>();

comboBox.addItem(1);
comboBox.addItem(2);
JComboBox组合框=新建JComboBox();
组合框。附加项(1);
组合框。附加项(2);
否则,您也可以尝试以下方法:

String[] birthYear = new String[currentYear]; //currentYear is an int variable
int inc=1;
for(int i=0;i<currentYear;i++)
{
    birthYear[i]= inc + "";
    inc++;
}

birthYearBox = new JComboBox(birthYear); 
String[]birthYear=新字符串[currentYear];//currentYear是一个int变量
int inc=1;

对于(int i=0;i如果您只想处理整数,可以选择一种方法:

JComboBox<Integer> comboBox = new JComboBox<>();

comboBox.addItem(1);
comboBox.addItem(2);
JComboBox组合框=新建JComboBox();
组合框。附加项(1);
组合框。附加项(2);
否则,您也可以尝试以下方法:

String[] birthYear = new String[currentYear]; //currentYear is an int variable
int inc=1;
for(int i=0;i<currentYear;i++)
{
    birthYear[i]= inc + "";
    inc++;
}

birthYearBox = new JComboBox(birthYear); 
String[]birthYear=新字符串[currentYear];//currentYear是一个int变量
int inc=1;
对于(int i=0;i