0

This is my first time creating a topic.

I have a TreeTableView with a few not editable TreeTableColumn, that are not the relevant, and one editable that is the reason of this topic. It's always necessary to double click to start editing the cell, or one click and one ENTER key. As my treeTableView may have a lot of rows, it may be kind of exhausting take one hand off the keybord and click to open the cell to edit the new value repteatly.

@FXML
private TreeTableView<CelulaTabelaLoteDigitar> tabela = new TreeTableView<>();

private TreeTableColumn<CelulaTabelaLoteDigitar, String> columnPrecoAtual = new TreeTableColumn<>("PREÇO ATUAL");

So, I want to do something like Excel does. After commiting a cell value with ENTER key, I want to go to the next row same column and be able to edit it too without being necessary to use mouse or arrows. I would like to do that only with one ENTER key, but It can be twice, one to commit and the other to open the cell to start edit.

enter image description here

I realized that after commiting a value the table lose focus, so I give it back and selected the next row inside of method setOnEditCommit. But the problem is that the row has others columns and I do not know how to "click" the column by code, so pressing ENTER key to open the cell doesn't work, since the column isn't selected.

columnPrecoAtual.setOnEditCommit(
        new EventHandler<TreeTableColumn.CellEditEvent<CelulaTabelaLoteDigitar, String>>() {

    @Override
    public void handle(TreeTableColumn.CellEditEvent<CelulaTabelaLoteDigitar, String> event) {

        TreeItem<CelulaTabelaLoteDigitar> rowValue = event.getRowValue();

        // ... code ...

        TreeItem<CelulaTabelaLoteDigitar> nextSibling = rowValue.nextSibling();
        tabela.requestFocus();
        tabela.getSelectionModel().select(nextSibling);

        // something to open the cell in column columnPrecoAtual in the nextSibling row OR
        // something to select the column columnPrecoAtual 

    }
});

In short, after ENTER key to commit I would like to start editing the next row if exists without using mouse or arrows. I want to start a CellEditEvent.

Gabriel Vianna
  • 151
  • 1
  • 6

1 Answers1

0

I have spent many days looking for some answers, but I didn't find even a question similar. I just can't believe that after one hour later posting the question I succeed after some tries. This is what I did:

tabela.getFocusModel().focus(event.getTreeTablePosition().getRow() + 1, columnPrecoAtual);

With this I need to use ENTER key twice, but solve the most part of my problem. Now I just need to make the scrollbar move down with the row edited.

EDITED:

And I finished, If I knew that the only thing necessary was posting the question I would done it earlier. I finished my issue with this:

tabela.scrollTo(event.getTreeTablePosition().getRow() + 1);

Thanks to anyone who maybe give a different answer. I hope this can help somebody.

Gabriel Vianna
  • 151
  • 1
  • 6
  • glad you found a solution and share it :) A bit unclear (probably due to the fact that you didn't show a mcve) - a) api to start an edit is something like `treeTable.edit(row, column)` b) the task of a editCommitHandler is to write the change back into the underlying data (which you do maybe in the left-out portion of your handler?) c) doing stuff like changing selection/focus/starting edit in the handler is tricky: the handler is called during the commit from the cell, the effect of state changes (on the current and other cells) is unspecified, might be unexpected ;) – kleopatra Apr 13 '18 at 09:05
  • @kleopatra thanks for for the clarification about mcve, I will remember this in future posts, as I see many questions with unnecessary code I tried to show the less as possible. a) I had tried it before, but nothing happened, I expected to have the same result as the image description (https://i.stack.imgur.com/UOjCt.png), just to open the cell. b) Indeed, that's what I do in omitted code. c) Yeah, I'm happy I got a solution. =] – Gabriel Vianna Apr 15 '18 at 02:57