I have a ComboBox defined as follows:

private String[] months = {"Month", "01", "02", "03", "04", "05", "06", "07", "08",
"09", "10", "11", "12"};
private JComboBox jComboBoxMonth = null;

and down further I have:

jComboBoxMonth = new JComboBox(months);

Now i am trying to do run an if statement which checks to see if the word "Month" is what is appearing in the ComboBox. So down further I have:

if (jComboBoxMonth.equals("Month") {
and my code is here.

Is the above test in the if statement being carried out, as i suspect that it isn't.

Anyone any ideas.

Thanks
Paidi

Re: comparing a value to a value in a jComboBox 80 80

No, you have to first call currently selected item String selectedOption = (String) jComboBoxMonth.getSelectedItem() and then you can compare it as you did it if (selectedOption.equals("Month")

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.