2014-02-14 2 views
0

Я хотел бы создать TableView, где ее столбцы имеют ссылки на тип:TableView с настраиваемым типом комбобоксе

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; 
} 

}

У меня есть

private TableView<Indicators> tableviewIndicators; 

В этой колонке

private TableColumn<Indicators, WindowsItem> tablecolumnFrame; 

public static class WindowsItem { 

InternalWindow chrt; 

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

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

} 

I хотелось бы выпадающий или choicebox, где каждый тип элемента является

WindowsItem 

Как я могу это сделать?

Я попробовал этот код

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(); 
        InternalWindow winItem; 

        for (int i = 0; i < itemsInTab; i++) { 
         if (chartsInTab.getChildren().get(i) instanceof InternalWindow) { 
          winItem = (InternalWindow) 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] 

ответ

2

Вы можете попробовать это:

private TableColumn<Indicators, WindowsItem> tablecolumnFrame; 

и

public static class Indicators { 

    private final SimpleStringProperty tool_col;   
    private final SimpleStringProperty pane_col; 
    private final SimpleBooleanProperty on_col; 
    private final SimpleObjectProperty<WindowsItem> chrt; 

    private Indicators(String tl, WindowsItem chrt, String pne, Boolean sel) { 
     this.tool_col = new SimpleStringProperty(tl);    
     this.chrt = new SimpleObjectProperty<>(chrt); 
     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 WindowsItem getChart(){ 
     return chrt.getValue(); 
    } 


    public void setChart(WindowsItem _chrt) { 
     chrt.set(_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 SimpleObjectProperty<WindowsItem> chartProperty() { 
     return chrt; 
    } 

    public SimpleStringProperty paneProperty() { 
     return pane_col; 
    } 
} 

быть осторожным:

public SimpleObjectProperty<WindowsItem> chartProperty() { 
     return chrt; 
    } 

в вашем предыдущем коде был:

public SimpleStringProperty chartProperty() { 
    return chart_col; 
} 

это является причиной для

SEVERE: javafx.scene.control.Control loadSkinClass Failed to load skin 'StringProperty 
+0

Большое спасибо, что это именно то, что мне было нужно –

Смежные вопросы