-1

I have a table with a column. Initially, the table is blank. I need to enter values at cell like Excel. I followed the question javafx-table-cell-editing and also JAVA Tutorial on TableView.

I coded like:

colCom1.setCellValueFactory(new PropertyValueFactory<>("C1"));
colCom1.setCellFactory(TextFieldTableCell.forTableColumn ());
colCom1.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<commonDataClass, String>>() {
        @Override
        public void handle(TableColumn.CellEditEvent<commonDataClass, String> t) {
            ((commonDataClass) t.getTableView().getItems().get(
                    t.getTablePosition().getRow())).setD1(t.getNewValue().toString());           
                tC1.setItems(myC1);
                System.out.println("Col1->" + colCom1.isVisible());
                tC1.refresh();
                tC1.setVisible(true);
            }
        }
    });

The issue I am facing is that after editing and pressing "ENTER" nothing appears in the cell (cell remains blank) while printing of data reveals that value has been properly entered.

Community
  • 1
  • 1
vegaonline
  • 43
  • 10

1 Answers1

-1

I modified setCellValueFactory as

colCom1.setCellValueFactory (
            new Callback<CellDataFeatures<commonDataClass, String>, ObservableValue<String>> () {
        public ObservableValue<String> call(
                CellDataFeatures<commonDataClass, String> p) {
            // p.getValue() returns the Person instance for a particular TableView row
            return p.getValue ().d1NameProperty ();
        }
    }); 

This clearly shows the content.

vegaonline
  • 43
  • 10
  • I don't understand the reason for the downvote. I was waiting for the help. I did not find any help and this is the way I tried to make it working? I also mentioned the resources which I was following. This place is not the place for my research. – vegaonline Jan 03 '17 at 08:11
  • The only purpose in answering your own question is to provide helpful information to other users. This answer is completely meaningless to anyone else because you don't explain why it fixes the problem, and you don't provide the code in the question that could possibly indicate that this was the problem. There is no way whatsoever, given the information you have provided, that this could be generalized to anything else. Since it serves no purpose to any other user, I downvoted it. – James_D Jan 04 '17 at 02:41
  • I mentioned that changing setCellValueFactory from the first post the second post shows entries in the cell. I am a novice and not expert like you. I posted to know whether I am following the right thing or not. I am here to get knowledge and not to stand in election. – vegaonline Jan 04 '17 at 07:02
  • "I posted to know whether I am following the right thing or not" suggests that this is really still part of your question, not an answer to your question. If so, you should delete the answer and edit the question to ask whatever it is you are now asking ("is this the correct approach", or "why does this work when the previous code doesn't", or whatever). As it stands, anyone who doesn't understand how cell value factories work would learn nothing from this, because your question doesn't even show your `commonDataClass`. Unless this is useful to other users, the downvote will remain. – James_D Jan 04 '17 at 13:07