2012-06-03 107 views
2

在我的代碼中,如果用戶選擇了Production,則可用的頻道會發生變化,但如果用戶決定選擇'Staging'或'Test',則應顯示頻道的完整列表。發生這種情況時,顯示的是[Ljava.lang.String;@1c23f1bb。什麼會糾正這種行爲?我是java的newby。將JCombobox值返回到'原始'列表

以下是我的代碼,當我將environmentCbx設置爲「Production」以外的內容時,我在社區組合框中沒有獲得原始字符串數組communityNameString

String communityNameString[] = {"Connection","CDK","Governors", "Community", "Committee", "Center","All States","Community_2","Sandbox"}; 


    environmentCbx.addActionListener(new ActionListener(){ 
    public void actionPerformed(ActionEvent ae) { 
     JComboBox environmentCbx = (JComboBox)ae.getSource(); 
     String environmentName = (String)environmentCbx.getSelectedItem(); 
     if("Production".equals(environmentName)) 
     { 
      communityCbx.removeAllItems(); 
      //communityCbx.addItem(productionCommunityNames); 
      communityCbx.addItem("Associate"); 
     } 
     else 
     { 
      communityCbx.removeAllItems(); 
      communityCbx.addItem(communityNameString); 
     } 

回答

4

在本example所示,可以有一個以上的ComboBoxModel,並且可以根據需要改變它們。只需構建兩個模型:一個包含完整列表,另一個包含子集。

附錄:更仔細地閱讀,符號[Ljava.lang.String;@1c23f1bb是應用於String []toString()方法的人工產物。預計項目是個人Object,例如String;您添加了一個完整的String實例數組。