2016-04-04 2 views
0
isText.setEditable(true); 
     isText.setCellValueFactory(new Callback<CellDataFeatures<TableItem, Boolean>, ObservableValue<Boolean>>() { 
      @Override 
      public ObservableValue<Boolean> call(CellDataFeatures<TableItem, Boolean> p) { 
       return new SimpleBooleanProperty(p.getValue().getIsText()); 
      } 
     }); 
     isText.setCellFactory(new Callback<TableColumn<TableItem, Boolean>, TableCell<TableItem, Boolean>>() { 
      @Override 
      public TableCell<TableItem, Boolean> call(TableColumn<TableItem, Boolean> p) { 
       return new CheckBoxTableCell<>(); 
      } 
     }); 

Вот мой код, я действительно хочу, чтобы проверить и снимите этот флажок и изменить исходные данные по методу I, определенной ниже,Как сделать мой CheckBoxTableCell доступным для редактирования в Javafx?

/** 
    * Set the boolean value of if this variable is viewed as text 
    */ 
    public void setIsText(boolean newVal) { 
     isText.set(newVal); 
    } 

Это моя полная реализация TableItem,

public class TableItem { 
    private final SimpleIntegerProperty index; 
    private final SimpleStringProperty variable; 
    private final SimpleBooleanProperty isText; 

    /** 
    * Constructor for TableItem 
    * 
    * @param index 
    *  index of the variable 
    * @param variable 
    *  variable name 
    * @param isText 
    *  initial boolean value of if it is viewed as a text or not 
    */ 
    public TableItem (int index, String variable, boolean isText) { 
     this.index = new SimpleIntegerProperty(index); 
     this.variable = new SimpleStringProperty(variable); 
     this.isText = new SimpleBooleanProperty(isText); 
    } 

    /** 
    * Get the boolean value of if this variable is viewed as text 
    * @return 
    *  the boolean value notifies if the variable is text or not 
    */ 
    public boolean getIsText() { 
     return isText.get(); 
    } 

    /** 
    * Set the boolean value of if this variable is viewed as text 
    */ 
    public void setIsText(boolean newVal) { 
     isText.set(newVal); 
    } 

    /** 
    * Get the index of the variable 
    * 
    * @return 
    *  the index 
    */ 
    public int getIndex() { 
     return index.get(); 
    } 

    /** 
    * Get the string representation of the variable 
    * 
    * @return 
    *  the string of the variable 
    */ 
    public String getVariable() { 
     return variable.get(); 
    } 
} 
+0

Так что же происходит, что это отличается от того, что вы хотите, чтобы это произошло? –

+0

Столбец окна редактирования недоступен, нажав – xxx222

+0

Вы сделали таблицу доступной для редактирования? –

ответ

2

Для редактирования TableCell s необходимо установить TableView.editable property в true.

Кроме того, вы создать новое свойство в вашем cellValueFactory, что означает значение редактируемого не будет собственностью TableView элементов, но новое свойство; значения ваших предметов не изменяются.

Изменение cellValueFactory к

new Callback<CellDataFeatures<TableItem, Boolean>, ObservableValue<Boolean>>() { 
    @Override 
    public ObservableValue<Boolean> call(CellDataFeatures<TableItem, Boolean> p) { 
     return p.getValue().isTextProperty(); 
    } 
} 

и добавьте следующий геттер свойство TableItem

public BooleanProperty isTextProperty() { 
    return this.isText; 
} 
Смежные вопросы