How to edit data with dynamic TableView with dynamic column in JAVAFX


Today This is the demo to show data from CSV for DAT file without make custom class on tableView in JavaFX 2.0. I call this TableView as Dynamic TableView because the tableview automatically manages the columns and rows.
On my research about the editable on tableView we must have a custom class and implement it to tableView to show as this demo ==>

But in this case I can not do it because we don't know how many column example with csv file or .dat file.... I want to do editable on this tableView in this case by add TextField into TableCell. How does it do without make custom class (because you do not how many column ...), and if it must make custom class then how about the design of custom class for this case?

Could you please help me?

    private void getDataDetailWithDynamic() {
    tblView.setPlaceholder(new Label("Loading..."));
        //            @Override

            try {
                File aFile = new File(txtFilePath.getText());
                InputStream is = new BufferedInputStream(new FileInputStream(aFile));
                Reader reader = new InputStreamReader(is, "UTF-8");

                BufferedReader in = new BufferedReader(reader);

                final String headerLine = in.readLine();
                final String[] headerValues = headerLine.split("\t");
                        for (int column = 0; column < headerValues.length; column++) {
                                    createColumn(column, headerValues[column]));

                // Data:

                String dataLine;
                while ((dataLine = in.readLine()) != null) {
                    final String[] dataValues = dataLine.split("\t");
                            // Add additional columns if necessary:
                            for (int columnIndex = tblView.getColumns().size(); columnIndex < dataValues.length; columnIndex++) {
                                tblView.getColumns().add(createColumn(columnIndex, ""));
                            // Add data to table:
                            ObservableList<StringProperty> data = FXCollections
                            for (String value : dataValues) {
                                data.add(new SimpleStringProperty(value));
            } catch (Exception ex) {
                System.out.println("ex: " + ex.toString());

    for(int i=0; i<tblView.getColumns().size(); i++) {
        TableColumn col = (TableColumn)tblView.getColumns().get(i);

private TableColumn createColumn(
        final int columnIndex, String columnTitle) {
    TableColumn column = new TableColumn(DefaultVars.BLANK_CHARACTER);
    String title;
    if (columnTitle == null || columnTitle.trim().length() == 0) {
        title = "Column " + (columnIndex + 1);
    } else {
        title = columnTitle;

            Callback<TableColumn, TableCell> cellFactory = new Callback<TableColumn, TableCell>() {
                public TableCell call(TableColumn p) {

                    System.out.println("event cell");
                    EditingCellData cellExtend = new EditingCellData();
                    return cellExtend;

    return column;

Thanks for your reading.

10/3/2013 2:54:41 AM

This is the best way to resolve it ==>

I'm really thank for your reading about that.


10/4/2013 3:16:16 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow