I have a MVC application written in java which has a form with three comboboxes in it. year / month / day and I want to change the number of days if the selection of year and month changed. in my viewer I just define the comboboxes
createComboBoxes( mainContentPage, "combobox name");
in my controller I have :
public class ComboBoxItemListener implements ItemListener
{
private int year=0;
private int month=0;
private int day=0;
public WeatherController c_wc;
@Override
public void itemStateChanged(ItemEvent event)
{
JComboBox comboBox = (JComboBox)event.getSource();
if (event.getStateChange() == ItemEvent.SELECTED)
{
//this area is my problem
if(comboBox.getName() == Helper.COMBOBOX_MONTH || comboBox.getName() == Helper.COMBOBOX_YEAR)
{
//definitely this line is not correct
c_wc.addDaysToComboBox(comboBox, year, month);
comboBox.setEnabled(true);
}
//rest is okay
switch(comboBox.getName())
{
case Helper.COMBOBOX_YEAR:
year = Integer.parseInt(comboBox.getSelectedItem().toString().trim());
break;
case Helper.COMBOBOX_MONTH:
KeyValue<String, Integer> selectedItem = (KeyValue<String,Integer>)event.getItem();
month = Integer.parseInt(selectedItem.getValue().toString());
break;
case Helper.COMBOBOX_DAY:
day = Integer.parseInt(comboBox.getSelectedItem().toString().trim());
break;
case Helper.COMBOBOX_AIRPORT:
break;
}
System.out.println(year + " " + month + " " + day);
}
}}
how can I change another component after firing some other event?
You can change the dependent combos' models, as shown in this example.
Alternatively, consider JCalendar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With