java - JComboBox itemstatechanged event -
i have 2 jcomboboxes want when select id first jcombobox 2nd jcombobox automatically select same index selected in first jcombobox.
i had implemented itemstatechanged of 1st jcombobox using code
private void driver_select_comboboxitemstatechanged(java.awt.event.itemevent evt) { int index1 = driver_select_id_combobox.getselectedindex(); int index2 = driver_select_combobox.getselectedindex(); if( index1 != index2 ){ driver_select_id_combobox.setselectedindex(index2); } }
but when add together itemstatechange event in 2nd jcombobox code
private void driver_select_id_comboboxitemstatechanged(java.awt.event.itemevent evt) { int index1 = driver_select_id_combobox.getselectedindex(); int index2 = driver_select_combobox.getselectedindex(); if( index1 != index2 ){ driver_select_combobox.setselectedindex(index1); } }
i error of stackoverflowerror. happened because 1st jcombobox changes state, changes state of 2nd jcombobox , 2nd jcombobox changes state, changes state of 1st jcombobox. , on. there's no ending calling itemstatechanged method.
can please help me how this? or have thought on how implement this? sorry, im new java.
java swing jcombobox stack-overflow
No comments:
Post a Comment