Results 1 to 3 of 3
  1. #1
    bahumbaba is offline Member
    Join Date
    Dec 2009
    Posts
    1
    Rep Power
    0

    Default Activate JComboBox 1 when object is selected in JComboBox 2...

    Hi forum

    I've looked around on the internet and even asked my programming teatcher, but either came out positive :)

    I need to activate a JComboBox, by having selected 1 element in a different JComboBox...

    Can anyone help me with this :confused:

  2. #2
    LittleRave is offline Member
    Join Date
    Dec 2009
    Location
    germany
    Posts
    15
    Rep Power
    0

    Default

    one way that definitely works is using an observer pattern ;)
    let the box1 observe the box2 and when selecting the object in box2 send an information to box1 so it can activate itself
    or to the superior component the box is in or to whatever component that can activate your box1 ;)

    im sure there are more solutions and i dont know if this is the best one but its definitely a good one

    for info on how to implement and use the observer pattern try wiki ;)

  3. #3
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

    Default

    Let master be the initial combobox
    and slave be the one that appears when a certain item is selected in master.

    In the managing application, do

    Java Code:
    master.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            // check to see if this is the trigger item
            // if so, do this
                slave.setSelectedIndex(index of desired item);
        }
    }
    Relevant (but skimpy) tutorials: JComboBox ItemListener

Similar Threads

  1. Replies: 5
    Last Post: 04-25-2009, 09:00 PM
  2. JComboBox
    By pinks_70986 in forum New To Java
    Replies: 2
    Last Post: 02-19-2009, 06:26 PM
  3. JComboBox
    By Fosters in forum AWT / Swing
    Replies: 0
    Last Post: 08-10-2008, 02:22 PM
  4. Help with jComboBox
    By Marcus in forum AWT / Swing
    Replies: 2
    Last Post: 07-02-2007, 12:08 AM
  5. jcombobox
    By Freddie in forum AWT / Swing
    Replies: 4
    Last Post: 05-11-2007, 01:48 AM

Posting Permissions

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