J'écris un programme simple; une partie de ce programme est une série de Combobox dans laquelle j'ai nourri des chaînes de mois (alpha), de jours (numériques) et d'années (numériques). Je voudrais en quelque sorte obtenir Java pour tirer la date, en termes de mois, jours et années, puis remplir automatiquement ces comboboxes avec le jour correct selon l'horloge du système.Série AutoFill de ComboBoxes - Java
Voici une partie de mon code:
public static final String[] MONTHS = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November",
"December"};
public static final String[] DAYS = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11",
"12", "13", "14", "15", "16", "17", "18", "19", "20",
"21", "22", "23", "24", "25", "26", "27", "28", "29",
"30", "31"};
public static final String[] YEARS = {"2015", "2014", "2013", "2012", "2011", "2010"};
Note to FORUMS: THIS ISN'T ALL THE CODE. I'VE JUST PROVIDED INFORMATION NECESSARY FOR THE QUESTION.
JLabel start = new JLabel("Start Date:");
if (shouldWeightX) {
c.weightx = .5;
}
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 1;
pane.add(start, c);
JComboBox MonthLong = new JComboBox();
if (shouldWeightX) {
c.weightx = 0;
}
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 1;
c.gridy = 1;
c.gridwidth = 1;
for(int i=0; i<MONTHS.length;i++) {
MonthLong.addItem(MONTHS[i]);
}
pane.add(MonthLong, c);
JComboBox DayLong = new JComboBox();
if (shouldWeightX) {
c.weightx = 1.0;
}
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 2;
c.gridy = 1;
c.gridwidth = 1;
for(int i=0; i<DAYS.length;i++) {
DayLong.addItem(DAYS[i]);
}
pane.add(DayLong, c);
JComboBox YearLong = new JComboBox();
if (shouldWeightX) {
c.weightx = 1.0;
}
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 3;
c.gridy = 1;
c.gridwidth = 1;
for(int i=0; i<YEARS.length;i++) {
YearLong.addItem(YEARS[i]);
}
YearLong.setSelectedItem("2013");
pane.add(YearLong, c);
Merci à l'avance.
Cela a fonctionné! Merci beaucoup. De plus, je connais les minuscules pour les variables, je suis en train d'éditer du code pour quelqu'un d'autre, mais dans cette question j'ai dit que c'était "à moi". Oups! Merci encore. – user2221125