2

I have made a gui with something like this:

String[] days29 = {"1",....."29"};
String[] days30 = {"1",....."30"};
String[] days31 = {"1",....."31"};
String[] mths = {"January",..."December"};

JComboBox months = new JComboBox(mths);
JComboBox days = new JComboBox();

public daysAdjuster(){
    if(months.getSelectedItem().equals.("January")){
        days = new JComboBox(days31);
    }else if(months.getSelectedItem().equals.("February")){
        days = new JComboBox(days29);
    }else if(months.getSelectedItem().equals.("April")){
        days = new JComboBox(days30);
    }

public static void main(String[] args){
// JFrame codes here
daysAdjuster();
}

What I want to do is that if I select the months with 31 days in JComboBox "months" the JComboBox "days" will output items using the "days31" string array and if I select months with 30 days only, it will output the string array "days30" in my days JComboBox.

But the only thing I'm getting is [[ days = new JComboBox(days31) ]] even though I've selected a different month. For example, if I select Febraury, it still displays a "days" JComboBox with "days31" string array with it. Obviously, I made a mistake in my daysAdjuster or just made it the wrong way, please correct my error, can't figure it out. Thanks in advance!

Notes:

  1. January is the default selected item in the jcombobox "months"

  2. Never made a spelling mistake in the if-else statement and in the string array declaration (in case you find some wrong spelling in my example)

  3. The "months" and "days" jcombobox are visible in the jframe, never made a mistake with the jcomboboxes in the gui I'm making right now

Harry Joy
  • 58,650
  • 30
  • 162
  • 207
Malice Sloth
  • 45
  • 3
  • 12

1 Answers1

4

I can make few points here:

  1. You have an extra . after equals in if conditions.
  2. Always use predefined arrays where-ever possible. Here you should use predefined array for months like following:

    String[] mths = (new DateFormatSymbols()).getMonths();

  3. Instead of re-initializing days combo box every time, use a model and change its values.

  4. References:
Community
  • 1
  • 1
Harry Joy
  • 58,650
  • 30
  • 162
  • 207