Reputation: 14873
From the following FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<VBox spacing="10" xmlns:fx="http://javafx.com/fxml">
<Label fx:id="_lru" styleClass="wizard-title-centered" />
<Label fx:id="_prompt" styleClass="wizard-label" />
<TableView fx:id="_tableVw" maxWidth="560" prefHeight="200" editable="true">
<columns>
<TableColumn fx:id="_name" prefWidth="220" editable="false" />
<TableColumn fx:id="_partNum" prefWidth= "80" editable="false" />
<TableColumn fx:id="_serialNum" prefWidth= "84" editable="true" />
<TableColumn fx:id="_calibrationDate" prefWidth="120" editable="true" />
<TableColumn fx:id="_available" prefWidth= "40" editable="false" />
</columns>
</TableView>
<Text fx:id="_note" wrappingWidth="550" styleClass="wizard-label" />
</VBox>
Associated to the following Java class:
public class Page extends AbstractPage<Data> implements Initializable {
@FXML private Label _lru;
@FXML private Label _prompt;
@FXML private TableView<Record> _tableVw;
@FXML private TableColumn<Record, String> _name;
@FXML private TableColumn<Record, String> _partNum;
@FXML private TableColumn<Record, String> _serialNum;
@FXML private TableColumn<Record, LocalDate> _calibrationDate;
@FXML private TableColumn<Record, Boolean> _available;
@FXML private Text _note;
@Override
public void initialize( URL location, ResourceBundle resources ) {
_lru .setText( _worker.getData()._tpsSoftName );
_prompt .setText( I18n.get("EXTERNAL_RC_PROMPT" ));
_name .setText( I18n.get("EXTERNAL_RC_NAME" ));
_partNum .setText( I18n.get("EXTERNAL_RC_PARTNUM" ));
_serialNum .setText( I18n.get("EXTERNAL_RC_SERIALNUM"));
_calibrationDate.setText( I18n.get("EXTERNAL_RC_CALIB" ));
_available .setText( I18n.get("EXTERNAL_RC_AVAILABLE"));
_note .setText( I18n.get("EXTERNAL_RC_NOTE" ));
_name .setCellValueFactory(new PropertyValueFactory<Record, String> ("name"));
_partNum .setCellValueFactory(new PropertyValueFactory<Record, String> ("partNum"));
_serialNum .setCellValueFactory(new PropertyValueFactory<Record, String> ("serialNum"));
_calibrationDate.setCellValueFactory(new PropertyValueFactory<Record, LocalDate>("calibrationDate"));
_available .setCellValueFactory(new PropertyValueFactory<Record, Boolean> ("available"));
_calibrationDate.setCellFactory(
new Callback<TableColumn<Record,LocalDate>, TableCell<Record,LocalDate>>() {
@Override public TableCell<Record,LocalDate> call( TableColumn<Record,LocalDate> c ) {
return new DatePickerCell<>(); }});
_available.setCellFactory(
new Callback<TableColumn<Record,Boolean>, TableCell<Record,Boolean>>() {
@Override public TableCell<Record,Boolean> call( TableColumn<Record,Boolean> c ) {
return new CheckBoxTableCell<>(); }});
}
@Override
public void processDone( boolean successfully ) {
_tableVw.getItems().setAll( _worker.getData()._resources);
}
}
Double-clicking serialNum columns doesn't activate the underlying TextField when "calibration date" column is editable. Why?
Upvotes: 1
Views: 1399
Reputation: 1270
This is because the default cell factory doesn't provide an editor as specified in the documentation of javafx.scene.control.cell.TextFieldTableCell.
By default, the TextFieldTableCell is rendered as a Label when not being edited, and as a TextField when in editing mode. The TextField will, by default, stretch to fill the entire table cell.
Adding the following code do the job.
_serialNum.setCellFactory( TextFieldTableCell.<Record>forTableColumn());
Upvotes: 2