Posted on 2013-07-23 11:02
TWaver 閱讀(1638)
評論(3) 編輯 收藏
屬性編輯頁面可以自己擴展editor,自定義A,B兩個Editor,B的值受A值改變而改變

思路很簡單,存在一個容器,給TDataBox添加網元屬性變化監聽器ElementPropertyChangeListener,當網元屬性A變化后,改變容器中的值,然后屬性B的Editor加載容器中的值,這樣就可以實現功能了
1 public void propertyChange(PropertyChangeEvent evt) {
2 String pro = TWaverUtil.getPropertyName(evt);
3 Element element = (Element)evt.getSource();
4 if("A".equals(pro)){
5 CustomUtil.ref = CustomUtil.getBRefs((Integer)element.getUserProperty("A"));
6 }
7 }
8 public static String[] getBRefs(int v){
9 switch(v){
10 case 1:
11 case 2:
12 return REF1;
13 default:
14 return REF2;
15 }
16 }
17 public Component getTableCellEditorComponent(JTable table, Object value,
18 boolean isSelected, int row, int column) {
19 JComboBox comboBox = (JComboBox)this.getComponent();
20 comboBox.removeAllItems();
21 if(CustomUtil.ref!=null){
22 for(int i=0;i<CustomUtil.ref.length;i++){
23 comboBox.addItem(CustomUtil.ref[i]);
24 }
25 }
26
27 return super.getTableCellEditorComponent(table, value, isSelected, row, column);
28 }
可運行代碼下載:
Archive