Results 1 to 3 of 3

Thread: JAVA: eliminate item from combobox ???

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    JAVA: eliminate item from combobox ???

    Hey,

    I having these 5 comboboxes. On selecting comboxox1 I need to eliminate the same item from the other 4 remaining comboboxes, so that it wont be possible to choose the same item more than once.Yet the 5 comboboxes are distinct and cannot be put into one combo.

    Hey any code or ideas are very much appreciated. Thanks loads

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: JAVA: eliminate item from combobox ???

    Which part are you having trouble with? To check when the selection was changed in a combo you need to implement an ItemListener like this :

    Code:
    class MyItemListener implements ItemListener {
    	Panel cp;
    	Choice c;
    	public MyItemListener(Choice c, Panel cp) {
    		this.cp = cp;
    		this.c = c;
        }
        public void itemStateChanged(ItemEvent e) {
    		if (e.getStateChange() == ItemEvent.SELECTED){
                            //do stuff here depending on the selection, change the items in the other combos
                            //CardLayout LM=(CardLayout)cp.getLayout();
                           
    			//LM.show(cp,(String)e.getItem());
    		}
    	}
    }
    And in your main code :

    Code:
    		c.addItemListener(new MyItemListener(c,cards));


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    Re: JAVA: eliminate item from combobox ???

    surely that is pretty easy, write a wrapper that takes in two combo boxes, n and n + 1
    add change listeners to n, then when there is a change you know which item to remove from n+ 1..

    where is the hardship?!

Posting Permissions

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



Click Here to Expand Forum to Full Width