当我制作一系列数组时,我的 JComboBox 显示空白条目
My JComboBox displays blank entry when I made a range of array
我正在尝试制作一个显示年份的 JComboBox GUI。我希望组合框从 1910 开始,但 GUI 显示一个空白条目,你只能在向下滚动时看到项目,尽管控制台从 1910 开始。我不知道我的组合框或我的for循环。有没有什么办法解决这一问题?初学者在这里:)
Integer[] year = new Integer[2020];
for(int i = 1910; i < year.length; i++) {
year[i] = i;
//System.out.println(year[i]);
}
yearBox = new JComboBox(year);
but the GUI shows a blank entry and you could only see the items when you scroll down
因为您的数组中有 1909 个空值,因为您只添加从 1910 开始的值。
for(int i = 1910; i < year.length; i++) {
year[i] = i;
//System.out.println(year[i]);
}
为什么要创建数组?
只需将项目直接添加到组合框即可:
yearBox = new JComboBox();
for(int i = 1910; i < year.length; i++) {
yearBox.addItem( Integer.valueOf(i) );
//System.out.println(year[i]);
}
我正在尝试制作一个显示年份的 JComboBox GUI。我希望组合框从 1910 开始,但 GUI 显示一个空白条目,你只能在向下滚动时看到项目,尽管控制台从 1910 开始。我不知道我的组合框或我的for循环。有没有什么办法解决这一问题?初学者在这里:)
Integer[] year = new Integer[2020];
for(int i = 1910; i < year.length; i++) {
year[i] = i;
//System.out.println(year[i]);
}
yearBox = new JComboBox(year);
but the GUI shows a blank entry and you could only see the items when you scroll down
因为您的数组中有 1909 个空值,因为您只添加从 1910 开始的值。
for(int i = 1910; i < year.length; i++) {
year[i] = i;
//System.out.println(year[i]);
}
为什么要创建数组?
只需将项目直接添加到组合框即可:
yearBox = new JComboBox();
for(int i = 1910; i < year.length; i++) {
yearBox.addItem( Integer.valueOf(i) );
//System.out.println(year[i]);
}