Re: do actions in ComboBox
Code :
private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {
if(evt.getStateChange()== evt.SELECTED && evt.getItem().toString().equals("Item 1"))
{
JOptionPane.showMessageDialog(null,"nmkbsdmf");
}
}
I think it may help you ... if you change used listener interface.
Re: do actions in ComboBox
You kind of answered your question as you asked it...
You said in your question, "according to the selected item".
The last two words that I quoted above are your answer. Anytime you want to know which item in your combobox is currently selected, you have two ways of finding out:
Code :
JComboBox1.getSelectedIndex(); // Which returns and int value, with 0 being the first item in the combobox.
JComboBox1.getSelectedItem(); // Which returns a String value that is the text of the item.
Either one of these will get you where you need to be. Just put the following in your JButtonActionPerformed event:
Code :
if ( JComboBox1.getSelectedItem().equals("What you are looking for") ) {
// Take some action for this item.
} else if ( JComboBox1.getSelectedItem().equals("Another string of text") ) {
// Take some different action.
} // ...etc...etc...etc
Hope this helps.
Cheers,
Sean C.
PekinSOFT Systems