0

I need to make each of the cells in a TableView into JFXTextArea. The first 4 columns are perfect and let me enter text into them. But the 5th column just isn't clickable.When I click on it the entire row gets selected. How do I get the 5th column to behave like the first 4?enter image description here

FXMLController.java

 @FXML
     private TableView<Person> table1;
     TableColumn indexCol = new TableColumn("S. No.");
     TableColumn desCol = new TableColumn("Description");
     TableColumn quantityCol = new TableColumn("Quantity"); 
     TableColumn unitCol = new TableColumn("Unit/(SGD)"); 
     TableColumn totalCol = new TableColumn("Total (SGD)"); 

void fillTable(){
     indexCol.setSortable(false);
     desCol.setSortable(false);
     quantityCol.setSortable(false);
     unitCol.setSortable(false);
     totalCol.setSortable(false);
     indexCol.setPrefWidth(50); 
     table1.getColumns().addAll(indexCol, desCol, quantityCol, unitCol ,totalCol);
    ObservableList<Person> data;    
    data = FXCollections.observableArrayList(
    new Person("Jack", "", "","", ""),
    new Person("Tom", "", "","", "")
    );
    indexCol.setCellValueFactory(
    new PropertyValueFactory<Person,String>("firstName")
    );
    desCol.setCellValueFactory(
    new PropertyValueFactory<Person,String>("lastName")
    );
     quantityCol.setCellValueFactory(     
             new PropertyValueFactory<Person,String>("email")
    );             
    unitCol.setCellValueFactory(
             new PropertyValueFactory<Person,String>("remark")
    );  
    totalCol.setCellValueFactory(new PropertyValueFactory<Person,String>("total"));       
    table1.setItems(data);                         
}

Person.java

public class Person {
    private JFXTextArea firstName;
    private  JFXTextArea lastName;
    private  JFXTextArea email;
    private JFXTextArea remark;  
    private  JFXTextArea total;

    Person(String fName, String lName, String email, String value, String total1) {
        this.firstName= new JFXTextArea();
        this.firstName.setText(fName);
        this.firstName.setEditable(false);
        this.remark = new JFXTextArea();   
        this.lastName = new JFXTextArea(); 
        this.email = new JFXTextArea(); 
        this.total = new JFXTextArea(); 

    }

    public JFXTextArea getFirstName() {
        return firstName;
    }
    public void setFirstName(JFXTextArea fName) {
        this.firstName = fName;
    }

    public JFXTextArea getLastName() {
        return lastName;
    }
    public void setLastName(JFXTextArea fName) {
        this.lastName =  fName;
    }

    public JFXTextArea getEmail() {
        return email;
    }
    public void setEmail(JFXTextArea fName) {
        this.email = fName;
    }


 public JFXTextArea getRemark() {
        return remark;
    }

    public void setRemark(JFXTextArea remark) {
        this.remark = remark;
    }

    public void settotal(JFXTextArea fName) {
            this.total = fName;
        }
     public JFXTextArea gettotal() {
            return total;
        }

}
SaberSz
  • 115
  • 1
  • 10
  • In addition to the issue noted in the duplicate (your getter and setter for Total does not follow standard capitalization naming conventions), you have other issues than just data not appearing, which is the title of your question. – jewelsea Jan 29 '18 at 20:56
  • Your Person model class should not contain or return nodes like JFXTextArea, it should just return basic types like Strings and ints. If you want a custom field like a JFXTextArea in a table cell you should create a cell factory (read the [Oracle JavaFX doc](https://docs.oracle.com/javase/8/javafx/user-interface-tutorial/table-view.htm) on how to do that). See the same doc for instructions on making editable cells (you have to do a lot more work for that: set the table to editable, add a setOnEditCommit method for the column, etc). – jewelsea Jan 29 '18 at 20:56
  • @jewelsea Thank You! – SaberSz Jan 29 '18 at 20:59
  • After you have read the doc and try to incorporate the code patterns from that into your code, if you have more issues, just create a new question with your updated code and question (single question per question). I'd advise just sticking with the standard JavaFX TextField control instead of the JFXTextArea (at least with regards to the editable TableView cells) until you get everything functionally working how you like - that way your code will be more like the Oracle TableView example and there is less chance of making any serious mistakes or undesired behaviour. – jewelsea Jan 29 '18 at 21:02

0 Answers0