2011-03-22 77 views
-1

我有7个jcomboboxes,说: customerInfo1 customerInfo2 customerInfo3 customerInfo4 customerInfo5 customerInfo6 customerInfo7使在一个JComboBox中的状态变化使不同的JComboBox

除了第一个被设置为的setEnabled(假)并拥有setSelectedItem(“请从下拉菜单中选择一个客户”)。我有最难的时间搞清楚我将如何去倾听customerInfo1上的状态变化,然后使customerInfo2 setEnabled(true)。而且,一旦启用了customerInfo2,状态更改事件对customerInfo3触发相同的事件,依此类推。基本上我不想让一个给定的customerInfo jcombobox被启用,直到在前一个选择了最初设置的东西之外的东西。非常感谢您的明确和具体帮助。

+0

你已经发布了同样的问题,甚至相同的标题: “http://stackoverflow.com/questions/5376546/make-a-selection-in-one-jcombobox-enable-a-different-jcombobox”。 – 2011-03-22 06:11:26

+0

认为可能改写的事情会帮助我得到更清晰的答案。 2个月前我开始学习Java。我目前正在努力处理我的项目的最后一个方面。 – Graham 2011-03-22 07:49:54

回答

-1

您需要在第一个组合框的change事件上调用JavaScript方法。

说如果你改变了第一个组合框的状态,这个JavaScript方法将被调用,并且它会根据你的需要改变其他组合框的状态。

对于所有其他组合框必须做同样的事情。

+0

你说我明白,但是它正在与我一起努力。 – Graham 2011-03-22 06:21:33

+0

哇,Javascript完全与问题无关,但感谢您的参与。 – Bombe 2011-03-22 07:36:20

0

您可以在组合框上添加焦点侦听器,以便如果组合框失去焦点,则可以检查有关条件并相应地采取行动!

if we have a combo box then we would add a focus listener on it and check the condition whether the check box is checked or not then add the required combobox. 

    JComboBox jb1; 
    jb1.addFocusListener(this); 

这是主要做和其他方法,下面的代码在同级别

 public void focusLost(FocusEvent fe) 
    { 
      //your code for enabling or disabling the combo box 
    } 

本应该做必要的事情

问候 ChArAnJiT