2014-02-07 2 views
1

У меня естьChoiceBox с пользовательским пунктом в TableView

private TableView<Indicators> tableviewIndicators; 

с колонкой

private TableColumn<Indicators, WindowsItem> tablecolumnFrame; 

public static class WindowsItem { 

    CustomInternalWindow chrt; 

    private WindowsItem(CustomInternalWindow _chrt) { 
     chrt = _chrt; 
    } 

    public String toString() { 
     return chrt.getTitle(); 
    } 

} 


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

    } 

    public String getTool() { 
     return tool_col.get(); 
    } 

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

    public WindowsItem getChart() { 
     return chrt; 
    }  

    public void setChart(WindowsItem _chrt) { 
     System.out.println("Indicators::setChart "+chrt.toString()); 
     chrt = _chrt; 
    } 

    public String getPane() { 
     return pane_col.get(); 
    } 

    public void setPane(String pne) { 
     pane_col.set(pne); 
    } 

    public Boolean getOn() { 
     return on_col.get(); 
    } 

    public void setOn(boolean sel) { 
     on_col.set(sel); 
    } 

    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.setCellValueFactory(new PropertyValueFactory<Indicators, WindowsItem>("chart")); 

Как я могу добавить выпадающий или choicebox в tablecolumnFrame?

Следующий код

tablecolumnFrame.setCellFactory(new Callback<TableColumn<Indicators, WindowsItem>, TableCell<Indicators, WindowsItem>>() { 
     @Override 
     public TableCell<Indicators, WindowsItem> call(TableColumn<Indicators, WindowsItem> param) { 
      TableCell<Indicators, WindowsItem> cell = new TableCell<Indicators, WindowsItem>() { 
       @Override 
       public void updateItem(WindowsItem item, boolean empty) { 
        super.updateItem(item, empty); 
        if(empty){ 
         return; 
        } 

        if (item != null) { 
         //final ChoiceBox<WindowsItem> choice = new ChoiceBox<>(); 
         final ComboBox<WindowsItem> choice = new ComboBox<>(); 
         int itemsInTab = chartsInTab.getChildren().size();// dimensione del contenuto del tab, compreso il pane 
         CustomInternalWindow winItem; 
         // 
         for (int i = 0; i < itemsInTab; i++) { 
          if (chartsInTab.getChildren().get(i) instanceof CustomInternalWindow) { 
           winItem = (CustomInternalWindow) chartsInTab.getChildren().get(i);          
           choice.getItems().add(new WindowsItem(winItem)); 
           //choice.getItems().add(winItem.toString()); 
           System.out.println("winItem.toString() "+winItem.toString()); 
          } 
         } 

возвращение эта ошибка

SEVERE: javafx.scene.control.Control loadSkinClass Failed to load skin 'StringProperty [bean: TableRow[id=null, styleClass=cell indexed-cell table-row-cell], name: skinClassName, value: com.sun.javafx.scene.control.skin.TableRowSkin]' for control TableRow[id=null, styleClass=cell indexed-cell table-row-cell] 
+0

что не работает? И чего вы хотите достичь? –

ответ

0

Почему вам нужно специальное свойство? Вы можете создать ListView с ComboBox вполне easily:

ObservableList<WindowsItem> windowsItems = FXCollections.observableArrayList(); 
    ObservableList<WindowsItem> data = FXCollections.observableArrayList(); 

    final ListView<WindowsItem> listView = new ListView<>(data); 
    listView.setEditable(true); 

    listView.setItems(data); 
    listView.setCellFactory(ComboBoxListCell.forListView(windowsItems)); 
Смежные вопросы