Search code examples
javafor-loopnetbeansjcombobox

Netbeans Combo Box Looping with a range number? 1900-1901 to 2000-2001


as the title says.

My codes in looping a year in a combo box in netbeans

 for (int i = 1900; i <= 2015 ; i ++){
        SchoolYear.addItem(i);
    }

SchoolYear is my combo box .

Now, i want to loop the display in my combo box 1900-1901 to 2014-2015? Should i do it on manual?no other way? Please give me some ideas .


Solution

  • Is this what you are looking for?

     for (int i = 1900; i < 2015 ; i ++){
            SchoolYear.addItem(i + "-" + (i+1)); // Output : 1900-1901
     }