Results 1 to 6 of 6
  1. #1
    cucucur is offline Member
    Join Date
    Apr 2011
    Posts
    20
    Rep Power
    0

    Default 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
    			
    		} 
            }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default

    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!

  3. #3
    camickr is online now Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    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 );
    	 }
    }

  4. #4
    cucucur is offline Member
    Join Date
    Apr 2011
    Posts
    20
    Rep Power
    0

    Default

    thank you so much for your help. the stack is:

    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)
    Regards!

  5. #5
    cucucur is offline Member
    Join Date
    Apr 2011
    Posts
    20
    Rep Power
    0

    Default

    hi! switch?? I'm afraid I don't understand you...

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default

    Ignore the spammer, I've already reported it and those meaningless posts will go away shortly.

    db

Similar Threads

  1. Key Events
    By rdjava in forum Java Gaming
    Replies: 0
    Last Post: 04-15-2011, 08:02 AM
  2. typed events vs untyped events.
    By Drun in forum SWT / JFace
    Replies: 0
    Last Post: 11-23-2009, 12:22 PM
  3. Need Help with events
    By Gatts79 in forum AWT / Swing
    Replies: 3
    Last Post: 09-23-2008, 03:18 AM
  4. swing events
    By chitra in forum AWT / Swing
    Replies: 3
    Last Post: 09-20-2008, 04:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •