2010-08-13 62 views
2

要求: 我有一個顯示在ComboBox中的字符串列表。這些字符串中的每一個都可以有一些屬性。這些屬性顯示在PropertyTable中。 ComboBox所選項目的屬性顯示在表格中。另外,我們使用PropertyTable編輯或設置屬性值到組合框中的選定項目。鏈接JComboBox&JTable

問題: 的那一刻我去選擇的ComboBox項,說物品1,新屬性值 ITEM1的所有在PropertyTable現有的屬性值設置。同樣,當我選擇這個item1時,我應該返回屬性值(,即item1之前的值取消選擇)回到PropertyTable?

當前實現邏輯:

我有每個PropertyTableCell,當單元格內容發生變化 TableCellListner

,它需要細胞的新的價值,並指定這個新屬性值的組合框的選擇項。每當選擇新項目時,將使用選定項目的屬性值刷新表格。

//before is Table initialization code 

Action action = new AbstractAction() 
{ 
    public void actionPerformed(ActionEvent e) 
    { 
     TableCellListener table = (TableCellListener)e.getSource(); 
     String selectedItem=(String)ComponentPropComboBox.getSelectedItem(); 
     if(table.getColumn()==1 && selectedItem!=null) 
     { 
      Property property=propertyMap.get(selectedItem); 

      else if(table.getRow()==0) 
      { 
       property.setProperty("MIN_LENGTH", (String)table.getNewValue()); 
       propertyMap.put(selectedItem, property); 
      } 

      else if(table.getRow()==1) 
      { 
       property.setProperty("STARTS_WITH_STRING", (String)table.getNewValue()); 
       propertyMap.put(selectedItem, property); 
      } 
      } 
    } 
}; 

TableCellListener tcl = new TableCellListener(PropertiesTable, action); 

如何實現克服上述挑戰這一要求?

PS: TableCellListner是不是Java通用庫。您可以通過以下鏈接查看代碼及其解釋:

我相信這個問題是顯而易見的!如果問題不清楚,請告訴我。提前感謝您的幫助&捐贈知識!

+2

你能更清楚一點嗎?你的「要求」是明確的,但你想要的不是。你說桌子必須更新嗎?一點點的代碼和一些屏幕會有幫助 – Nivas 2010-08-13 05:33:52

+0

你的代碼有一個錯誤。如果在屬性聲明之後,你還有其他的東西,如果沒有。如果應該是第一個其他人呢? 我同意尼瓦斯的觀點,但我仍然沒有清楚地知道問題所在。 – I82Much 2010-08-24 03:21:08

回答

1

在偵聽JComboBox選擇的代碼中。在它的開始,它設置了一個布爾值,該項目正在被更改。然後讓表格刷新代碼忽略布爾值設置時發生的事件。完成刷新後,將布爾值設置回來。