Results 1 to 6 of 6
Thread: JComboxBox events
- 04-18-2011, 04:09 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 20
- Rep Power
- 0
JComboxBox events
hi!! I want to do 3 JComboxBox, the second one depends on the first one value, and the third one depends on the second one.
My problem is when the first one changes I have a AWT-EventQueue-0 Exception.
I suppose my problem will be solved with a "on change" event or similar, does it exist in Java???
Thank you so much!!
Java Code:users = new JComboBox(user); address = new JComboBox(); phone = new JComboBox(); listenerUsers listenUsers = new listenerUsers(); users.addActionListener(listenUsers); public class listenerUsers implements ActionListener { public void actionPerformed (ActionEvent e) { ArrayList<String> addr = remoto.returnAdd(conn,RFID.getSelectedItem().toString()); Object[] Addre = addr.toArray(); address.removeAllItems(); for (int i = 0; i<Addre.length; i++){ address.addItem(Addre[i]); } listenerAddress listenaddress = new listenerAddress(); address.addActionListener(listenAddress); } } public class listenerAddress implements ActionListener { public void actionPerformed (ActionEvent e) { ArrayList<String> IBUTTONS = remoto.returnPhone(conn,address.getSelectedItem().toString()); //ERROR } }
- 04-18-2011, 04:18 PM #2
That's not the Exception, that's simply the Thread that's running when the Exception is thrown. Can you copy and paste the full stack trace with the actual Exception?
Also- how would an "on change" listener be different from an ActionListener?How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-18-2011, 05:46 PM #3
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Java Code:import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; public class ComboBoxTwo extends JFrame implements ActionListener { private JComboBox mainComboBox; private JComboBox subComboBox; private Hashtable subItems = new Hashtable(); public ComboBoxTwo() { String[] items = { "Select Item", "Color", "Shape", "Fruit" }; mainComboBox = new JComboBox( items ); mainComboBox.addActionListener( this ); // prevent action events from being fired when the up/down arrow keys are used // mainComboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); getContentPane().add( mainComboBox, BorderLayout.WEST ); // Create sub combo box with multiple models subComboBox = new JComboBox(); subComboBox.setPrototypeDisplayValue("XXXXXXXXXX"); // JDK1.4 getContentPane().add( subComboBox, BorderLayout.EAST ); String[] subItems1 = { "Select Color", "Red", "Blue", "Green" }; subItems.put(items[1], subItems1); String[] subItems2 = { "Select Shape", "Circle", "Square", "Triangle" }; subItems.put(items[2], subItems2); String[] subItems3 = { "Select Fruit", "Apple", "Orange", "Banana" }; subItems.put(items[3], subItems3); // mainComboBox.setSelectedIndex(1); } public void actionPerformed(ActionEvent e) { String item = (String)mainComboBox.getSelectedItem(); Object o = subItems.get( item ); if (o == null) { subComboBox.setModel( new DefaultComboBoxModel() ); } else { subComboBox.setModel( new DefaultComboBoxModel( (String[])o ) ); } } public static void main(String[] args) { JFrame frame = new ComboBoxTwo(); frame.setDefaultCloseOperation( EXIT_ON_CLOSE ); frame.pack(); frame.setLocationRelativeTo( null ); frame.setVisible( true ); } }
- 04-19-2011, 07:49 AM #4
Member
- Join Date
- Apr 2011
- Posts
- 20
- Rep Power
- 0
thank you so much for your help. the stack is:
Regards!Java Code:Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at alquilar$listenerAddress.actionPerformed(alquilar.java:88) at javax.swing.JComboBox.fireActionEvent(Unknown Source) at javax.swing.JComboBox.contentsChanged(Unknown Source) at javax.swing.JComboBox.intervalRemoved(Unknown Source) at javax.swing.AbstractListModel.fireIntervalRemoved(Unknown Source) at javax.swing.DefaultComboBoxModel.removeAllElements(Unknown Source) at javax.swing.JComboBox.removeAllItems(Unknown Source) at alquilar$listenerUsers.actionPerformed(alquilar.java:77) at javax.swing.JComboBox.fireActionEvent(Unknown Source) at javax.swing.JComboBox.setSelectedItem(Unknown Source) at javax.swing.JComboBox.setSelectedIndex(Unknown Source) at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(Unknown Source) at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$000(Unknown Source) at java.awt.EventQueue$1.run(Unknown Source) at java.awt.EventQueue$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$2.run(Unknown Source) at java.awt.EventQueue$2.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
- 04-19-2011, 10:59 AM #5
Member
- Join Date
- Apr 2011
- Posts
- 20
- Rep Power
- 0
hi! switch?? I'm afraid I don't understand you...
- 04-19-2011, 11:55 AM #6
Similar Threads
-
Key Events
By rdjava in forum Java GamingReplies: 0Last Post: 04-15-2011, 08:02 AM -
typed events vs untyped events.
By Drun in forum SWT / JFaceReplies: 0Last Post: 11-23-2009, 12:22 PM -
Need Help with events
By Gatts79 in forum AWT / SwingReplies: 3Last Post: 09-23-2008, 03:18 AM -
swing events
By chitra in forum AWT / SwingReplies: 3Last Post: 09-20-2008, 04:57 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks