2014-05-12 9 views
0

사용 사례 : 사용자가 요소를 조합하여 최종 솔루션으로 결합하는 기능을 제공하려고합니다. 요소에는 버전이 있습니다. 그렇게하기 위해 포함 할 요소를 정의하기 위해 CheckBoxes를 조합 한 다음 선택한 요소에 대해 어떤 버전을 사용해야하는지 정의하기 위해 각 확인란 아래에 중첩 된 라디오 버튼이 필요합니다.JavaFX : 라디오 버튼으로 트리보기 만들기

현재 ControlsFX의 CheckTreeView 컨트롤을 사용하고 있습니다. 하지만 Tree의 CheckBoxTreeItem에 RadioButtonMenuItems를 자식으로 두는 방법을 찾을 수 없습니다. CheckBoxTreeItem을 RadioButton처럼 보이도록 변경하는 방법이 있습니까?

현재 해결책은 모든 트리 노드에 대해 CheckBoxItems를 사용하고 있지만 버전 정의에 사용되는 노드는 라디오 버튼처럼 작동합니다. 하나를 선택하면 나머지는 선택 취소됩니다.

접근 방법에 대한 아이디어가 있으십니까?

편집 : 새로운 질문 + 당신은 필요에 따라 그 체크 박스 나 라디오 버튼을 표시합니다 TreeCellFactory 사용자 정의를 만들어야합니다 우선은 여기를 here

답변

1

코드를 기록했다. 다음과 같이합니다 :

public class TreeCellFactory implements Callback<TreeView<Object>,TreeCell<Object>> 
{ 
    @Override 
    public TreeCell call(TreeView param) 
    { 
     return new TreeCell<Object>() 
     { 
      private final CheckBox check = new CheckBox(); 
      private final RadioButton radio = new RadioButton(); 
      private Property<Boolean> prevRadioProp; 
      { 
       setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 
      } 

      @Override 
      public void updateItem(Object item, boolean empty) 
      { 
       if (prevRadioProp != null) 
       { 
        radio.selectedProperty().unbindBidirectional(prevRadioProp); 
        prevRadioProp = null; 
       } 
       check.selectedProperty().unbind(); 

       if (! empty && item != null) 
       { 
        Property<Boolean> selectedProp = ....; 

        if (getTreeItem().isLeaf()) // display radio button 
        { 
         radio.setText(...); 
         radio.selectedProperty().bindBidirectional(selectedProp); 
         prevRadioProp = selectedProp; 
         setGraphic(radio); 
        } 
        else       // display checkbox 
        { 
         check.setText(...); 
         check.selectedProperty().bind(selectedProp); 
         setGraphic(check); 
        } 
       } 
       else 
       { 
        setGraphic(null); 
        setText(null); 
       } 
      } 
     }; 
    } 
} 
+0

감사합니다. – melkhaldi

관련 문제