2013-03-18 3 views
-1

데이터베이스의 데이터를 표시하려고합니다. ListView를 사용하기 때문에 javaFx 1.3에는 TableView가 없습니다. 그러나, 내가 listview에 텍스트 상자를 넣을 때, 그것은 잘 수행되지 않습니다. 데이터를 가져 오는 데 문제가 발생합니다. 아무도 내게 그것의 텍스트 상자와 listview에 대한 코드를 줄 수 있고 그것도 가져오고 데이터를 업데이 트하십시오.javafx 1.3 listview

답변

1
var lv_dept_nm:String = ""; 

var lv_dept_des:String = ""; 

var lv_dept_name:TextBox; 

var lv_dept_desc:TextBox; 

var lv_dept_upBtn: Button; 

var lv_dept_flag:Boolean = false; 

var lv_dept_ind: Integer; 

var lv_dept_len: Integer = 0; 

var lv_dept_size:Integer = 0; 

function removeLastChar(str: String) 

{ 

    var string; 

    if(str != "") 
    { 
     string = str.substring(0, str.length()-1); 
    } 
    else 
    { 
     string = str; 
    } 
    return string; 
} 

var viewDepartmentListView: ListView = ListView 

{ 

     items: bind [dept_choicebox_item] 

     layoutInfo: LayoutInfo{height:bind lv_dept_size} 
     layoutX: 170 
     layoutY: 150 
     width: 500 
     cellFactory: function() { 
      var listCell: ListCell;   

      if(dept_choicebox_item.size() > 5) 
      { 
       lv_dept_size = 55 * 5; 
      } 
      else 
      { 
       lv_dept_size = 55 * dept_choicebox_item.size(); 
      } 
      listCell = ListCell { 
       node : HBox { 
        width: 200 
        content: [ 
         VBox { 
          spacing: 10 
          content: [ 
           Label { 
            text: bind dept_choicebox_item[listCell.index] 
            visible: bind not listCell.empty and not lv_dept_flag or not listCell.selected or (lv_dept_ind != listCell.index) 
           } 
           lv_dept_name = TextBox 
           { 
            promptText: bind dept_choicebox_item[listCell.index] 
            onKeyPressed: function(ke: KeyEvent) 
            { 
             if(ke.code.toString() == "VK_BACK_SPACE") 
             { 
              lv_dept_len = lv_dept_nm.length(); 
              lv_dept_nm = removeLastChar(lv_dept_nm); 
             } 
            } 
            onKeyTyped: function(e:KeyEvent) 
            { 
             if(lv_dept_len != 0) 
             { 
              lv_dept_len = 0; 
             } 
             else if(lv_dept_nm == "") 
             { 
              lv_dept_nm = e.char; 
             } 
             else 
             { 
              lv_dept_nm = '{lv_dept_nm}{e.char}'; 
             } 
            } 

            columns: 12 
            visible:bind not listCell.empty and lv_dept_flag and listCell.selected and (lv_dept_ind == listCell.index) 
           } 
          ] 
         } 
         VBox { 
          spacing: 10 
          content: [ 
           Label { 
            text: bind description[listCell.index] 
            visible: bind not listCell.empty and not lv_dept_flag or not listCell.selected or (lv_dept_ind != listCell.index) 
           } 
           lv_dept_desc = TextBox 
           { 
            promptText: bind description[listCell.index] 
            onKeyPressed: function(ke: KeyEvent) 
            { 
             if(ke.code.toString() == "VK_BACK_SPACE") 
             { 
              lv_dept_len = lv_dept_des.length(); 
              lv_dept_des = removeLastChar(lv_dept_des); 
             } 
            } 
            onKeyTyped : function(e: KeyEvent) 
            { 
             if(lv_dept_len != 0) 
             { 
              lv_dept_len = 0; 
             } 
             else if(lv_dept_des == "") 
             { 
              lv_dept_des = e.char; 
             } 
             else 
             { 
              lv_dept_des = '{lv_dept_des}{e.char}'; 
             } 
            } 
            columns: 12 
            visible:bind not listCell.empty and lv_dept_flag and listCell.selected and (lv_dept_ind == listCell.index) 
           }         
          ] 
         } 
         VBox{ 
          spacing: 10 
          content: [ 
           Button { 
            vpos: VPos.TOP; 
            text: "Edit" 
            visible: bind not listCell.empty and (not lv_dept_flag or not listCell.selected or (lv_dept_ind != listCell.index)) 
            action: function() { 
             lv_dept_ind = listCell.index; 
             lv_dept_flag = true; 
            } 
           } 
           lv_dept_upBtn = Button { 
            vpos: VPos.TOP; 
            text: "Update" 
            visible: bind not listCell.empty and lv_dept_flag and listCell.selected and (lv_dept_ind == listCell.index) 
            action: function() { 
             cs = cn.prepareCall("call update_dept(?,?,?)"); 
             cs.setString(1, '{dept_choicebox_item[listCell.index]}'); 
             cs.setString(2, '{lv_dept_nm}'); 
             cs.setString(3, '{lv_dept_des}'); 
             cs.executeUpdate(); 
             dept_choicebox_item[listCell.index] = lv_dept_nm; 
             description[listCell.index] = lv_dept_des; 
             lv_dept_flag = false; 
             lv_dept_nm = ""; 
             lv_dept_des = ""; 
            } 
           } 
          ] 
         } 
         VBox{ 
          spacing: 10 
          content: [ 
           Button { 
            vpos: VPos.TOP; 
            text: "Delete" 
            visible: bind not listCell.empty and (not lv_dept_flag or not listCell.selected or (lv_dept_ind != listCell.index)) 
            action: function() { 
             cs = cn.prepareCall("call delete_dept(?)"); 
             cs.setString(1,'{dept_choicebox_item[listCell.index]}'); 
             cs.executeUpdate(); 
             delete dept_choicebox_item[listCell.index] from dept_choicebox_item; 
             delete description[listCell.index] from description; 
             lv_dept_size = 55 * dept_choicebox_item.size(); 
            } 
           } 
          ] 
         } 
         ] 
         }    
      } 
     } 
     visible:true; 
    }; 
관련 문제