Java Jcombobox Removeallitems Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies how to reset combobox in java of this site About Us Learn more about Stack Overflow the company
Jcombobox Removeallitems Nullpointerexception
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges jcombobox remove all items Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a
Remove Item From Jcombobox Java
minute: Sign up Having trouble with Combobox.removeAllItems(); method up vote 1 down vote favorite I hope my problem is really basic but it is driving me crazy :( I have uploaded a video of the problem in action https://www.youtube.com/watch?v=dd8Qg5DFMpg&feature=youtu.be I am using a jXDatePicker to pick a date, and add a list of employee Id's in a combobox. First Time, the code jcombobox add items runs smoothly. However, when I choose the date second time on the jXDatePicker, it throws a null pointer exception. Third time around code is again working fine but the employee names are not being populated in the textbox, when I choose a value from the combobox. Strangely employeeIds in the combobox are being populated fine. I have traced the problem to removeallitems() combobox line below, because when I remove this line, it does not throw a null pointer exception. Below are the codes for action events of datepicker and combobox. combobox is named empbx. private void jXDatePicker1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: empbx.removeAllItems();/////THIS LINE OVER HERE d = jXDatePicker1.getDate(); emp1=ControllerClass.searchEmpAvalibility(String.valueOf(d.getDay())); for (Employee e : emp1) { if (e != null) { empbx.addItem(e.getEmployeeId()); } } //unrelated code //TableClean(); //TableuncheckEmp(); //TableFill(); } private void empbxActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: emp=ControllerClass.getEmployees(); Object s = empbx.getSelectedItem(); for (Employee e : emp) { if (e != null) { if (Integer.parseInt(s.toString()) == e.getEmployeeId()) { empftxt.setText(e.getFirstName()); empltxt.setText(e.getLastName()); } } } } Error log: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at newnapit.ScheduleGUI.empbxActionPerformed(ScheduleGUI.java:855) at newnapit.ScheduleGUI.access$800(ScheduleGUI.java:42)
here for a quick overview of the site Help Center
How To Clear Combobox In Java Swings
Detailed answers to any questions you might have Meta
How To Clear Jcombobox In Netbeans
Discuss the workings and policies of this site About Us Learn more about Stack Overflow how to update combobox in java the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x http://stackoverflow.com/questions/28789001/having-trouble-with-combobox-removeallitems-method Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Java Swing Combobox removeAllItems calling ItemStateChanged also? up vote 2 down vote favorite 1 My code is quite http://stackoverflow.com/questions/10202718/java-swing-combobox-removeallitems-calling-itemstatechanged-also simple actually. I saw a simple and similar code was from this article. At first, I have 1 combobox. I have a listener on it called itemStateChanged(). My purpose to add into this listener is that; "to execute some code when user click (select) an item from its dropbox". Cmb_ItemCategory = new javax.swing.JComboBox(); Cmb_ItemCategory.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Loading..." })); Cmb_ItemCategory.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { Cmb_ItemCategoryItemStateChanged(evt); } }); private void Cmb_ItemCategoryItemStateChanged(java.awt.event.ItemEvent evt) { if(evt.getStateChange() == java.awt.event.ItemEvent.SELECTED){ System.err.println("Sombody click or change my model content"); } } Behind the code, I grab some data, and then calling a method of removeAllItems() . And then I set a new Model (from new data) into it. -- at another line of code --- Cmb_ItemCategory.removeAllItems(); Cmb_ItemCategory.setModel(newModel); I juz realized that my itemStateChanged() is called when i do the removeAllItem() method. called once. So, How to
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers http://stackoverflow.com/questions/16878694/exception-removing-all-combo-box-items-with-jcombobox-open or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it http://forums.codeguru.com/showthread.php?35182-HELP!-JComboBox-s-removeAllItems()-error only takes a minute: Sign up Exception Removing all Combo Box Items with JComboBox Open up vote 0 down vote favorite I need to remove all the elements at my JComboBox, using .removeAllItems() it works fine! But I notice that how to there is a small problem, maybe a bug? I don't know. If I leave the JComboBox opened, and then try to remove all the items, an exception is thrown: Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0 I tryed to close the popup before calling the removeAllItems, like this: private void removeAllClassesAvailable() { classeComboBox.hidePopup(); classeComboBox.removeAllItems(); } But still didn't work out ! Maybe because my JComboBox is inside a JTable? java swing jcombobox removeall share|improve this question edited Jan 17 '14 combobox in java at 9:07 Tshepang 4,6991059103 asked Jun 2 '13 at 0:42 DarkLink 95621745 Can you show the line that is throwing the exception? –SJuan76 Jun 2 '13 at 0:44 3 Hopefully someone will be able to answer this soon. If not, consider adding more information and code, best an sscce. –Hovercraft Full Of Eels Jun 2 '13 at 0:45 ......... or not. –Hovercraft Full Of Eels Jun 2 '13 at 4:57 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted Looks like one of the listeners added to the combobox tries to process selection. Try to remove the listener(s) from the combo before removing items and readd after. share|improve this answer answered Jun 2 '13 at 8:11 StanislavL 42.2k62859 Fixed thanks mate ;) –DarkLink Jun 3 '13 at 2:10 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged java swing jcombobox removeall or ask your own question. asked 3 years ago viewed 1220 times active 2 years ago Blog Stack Overflow Podcast #91 - Can You Stump Nick Craver? Relat
Forum Java Programming Java Programming HELP! -- JComboBox's removeAllItems() error If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register or Login before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Results 1 to 3 of 3 Thread: HELP! -- JComboBox's removeAllItems() error Tweet Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode March 12th, 2000,10:36 PM #1 125 View Profile View Forum Posts Junior Member Join Date Feb 2000 Posts 11 HELP! -- JComboBox's removeAllItems() error I was clearing out a JComboBox using MyJComboBox.removeAllItems(). I checked the combo box before the command got excuted and the Item count was positive. However, I got the following error (kc.loadCampaigns() is my method that calls the removeAllItems() method). Anybody can help me on this one? Thank you very much. Lifeng Exception occurred during event dispatching: java.lang.IllegalArgumentException: setSelectedIndex: -1 out of bounds at com.sun.java.swing.JComboBox.setSelectedIndex(JComboBox.java:384) at com.sun.java.swing.plaf.basic.BasicComboPopup$ListSelListener.valueChanged(BasicComboPopup.java:441) at com.sun.java.swing.JList.fireSelectionValueChanged(JList.java:885) at com.sun.java.swing.JList$6.valueChanged(JList.java:911) at com.sun.java.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:133) at com.sun.java.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:113) at com.sun.java.swing.DefaultListSelectionModel.clearSelection(DefaultListSelectionModel.java:157) at com.sun.java.swing.DefaultListSelectionModel.removeIndexInterval(DefaultListSelectionModel.java:514) at com.