Results 1 to 2 of 2
  1. #1
    Kibadachi is offline Member
    Join Date
    Dec 2013
    Rep Power

    Lightbulb Filter products through 2 combo boxes or 1 combo box and 1 check box

    Hey guys . I am atm trying to design the GUI for a restaurant application . After reading the tutorials and API about how to use the ComboBox and the Checkbox i managed to make the GUI work but i still can't figure out how to synchronize the ComboBoxes and CheckBoxes so that when i choose an option from the first ComboBox to filter the products by the option i choose and when i choose the option from the second ComboBox to filter the results from the first Box and display the final results .. Can anyone pls help me with the method required to bind the 2 ComboBoxes ?

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Rep Power

    Default Re: Filter products through 2 combo boxes or 1 combo box and 1 check box

    Not sure I understand the question but in this example the contents of the second combo box change when an item is selected in the first combo box:
    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() );
    			subComboBox.setModel( new DefaultComboBoxModel( (String[])o ) );
    	public static void main(String[] args)
    		JFrame frame = new ComboBoxTwo();
    		frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
    		frame.setLocationRelativeTo( null );
    		frame.setVisible( true );

Similar Threads

  1. Combo Boxes HELP
    By nksjolinder1 in forum New To Java
    Replies: 8
    Last Post: 10-25-2011, 05:44 AM
  2. Replies: 12
    Last Post: 05-04-2011, 09:31 PM
  3. Comparing two combo boxes
    By Wednesday Bass in forum AWT / Swing
    Replies: 2
    Last Post: 03-27-2011, 12:28 PM
  4. multiple combo boxes
    By simo_mon in forum AWT / Swing
    Replies: 1
    Last Post: 07-22-2010, 11:57 AM
  5. [SOLVED] Combo Boxes Automation
    By dbashby in forum New To Java
    Replies: 3
    Last Post: 03-27-2009, 01:39 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