2013-10-30 11 views
1

나는 같은 클래스가 유사한 상황으로자바 FX 2] 선택은

Rendering a POJO with JavaFX 2

,210

하지만 선택 바

편집을 사용 :이 내 상황

이다 : 그것의 열 중 하나에 내가 myClass가 유형의 객체에서 문자열을 설정할 필요가 어디 있으며, toString를 사용하여있는 tableView이() 메소드를 호출합니다.

나는이 방법을 사용하는 것을 시도했다 (여기서 myClass가 -> CustomInternalWindow 클래스)

public static class Indicators{ 
     private final SimpleStringProperty tool_col; 
     private final SimpleStringProperty chart_col; 
     private final SimpleStringProperty pane_col; 
     private final SimpleBooleanProperty on_col; 

     private Indicators(String tl, CustomInternalWindow chrt, String pne, Boolean sel){ 
      this.tool_col = new SimpleStringProperty (tl); 
      if (chrt == null) { 
       this.chart_col = null;     
      } 
      else { 
       this.chart_col = new SimpleStringProperty (chrt.toString()); 
      } 
      this.pane_col = new SimpleStringProperty (pne); 
      this.on_col = new SimpleBooleanProperty (sel); 

     } 
     public String getTool(){ 
      return tool_col.get(); 
     } 
     public void setTool(String tl){ 
      tool_col.set(tl); 
     } 
... 

public SimpleBooleanProperty onProperty() { 
      return on_col; 
     } 
     public SimpleStringProperty toolProperty(){ 
      return tool_col; 
     } 
     public SimpleStringProperty chartProperty(){ 
      return chart_col; 
     } 
     public SimpleStringProperty paneProperty(){ 
      return pane_col; 
     } 
} 

tablecolumnFrame.setCellFactory(new Callback<TableColumn<Indicators, CustomInternalWindow>, TableCell<Indicators, CustomInternalWindow>>(){ 
     @Override 
     public TableCell<Indicators, CustomInternalWindow> call(TableColumn<Indicators, CustomInternalWindow> param){ 
      TableCell<Indicators, CustomInternalWindow> cell = new TableCell<Indicators, CustomInternalWindow>(){ 

      @Override 
      public void updateItem(CustomInternalWindow item, boolean empty) { 
        super.updateItem(item, empty); 
        if (item != null) { 
         ChoiceBox<CustomInternalWindow> choiceChart = new ChoiceBox<>(newprojectx.NewProjectXController.windowsPlotted); 
         choiceChart.setConverter(new CustomInternaWindowStringConverter()); 
         choiceChart.getSelectionModel().select(item); 
         choiceChart.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<CustomInternalWindow>() {           
            @Override 
            public void changed(
            final ObservableValue<? extends CustomInternalWindow> ov, final CustomInternalWindow oldValue, final CustomInternalWindow newValue) { 
             if (!isEditing()) { 
              final TableView table = getTableView(); 
              if (table != null) { 
               table.edit(getTableRow().getIndex(), getTableColumn()); 
              } 
             } 
             commitEdit(newValue); 
            } 
           }); 
         setGraphic(choiceChart); 
        } 
       } 
      };    
      return cell; 
     } 
    }); 

하지만 windowsPlotted 목록에서 문자열을 표시 할 수 없습니다입니다

업데이트 : 나는이 문제에 여전히 고심하고있다. 어떤 도움이나 제안도 정말 고맙게 생각한다.

답변

4

당신은 당신의 myClass가 인스턴스와] 선택에 표시된 값 사이에 변환하는 StringConverter을 지정할 수 있습니다.

이 작업은 setConverter() 방법으로 수행됩니다.

예를 들어

가 :

ChoiceBox<myClass> choiceChart = new ChoiceBox<>(); 
choiceChart.setConverter(new MyClassConverter()); 
choiceChart.setItems(myClassList); 

class MyClassConverter extends StringConverter<myClass> { 

    public myClass fromString(String string) { 
    // convert from a string to a myClass instance 
    } 

    public String toString(myClass myClassinstance) { 
    // convert a myClass instance to the text displayed in the choice box 
    } 
} 
+0

좀 더 자세한 코드 내 질문을 편집, 난 여전히 심지어 귀하의 회신 후 문제가 –