2011-03-22 25 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