JavaFX: Combo box focus issue in table view

1.2k views Asked by At

Scenario: I have created a table view in JavaFx with 2 columns. I have populated the table with some sample data. Now, I have to edit the cells of my table. For that I created a new class (ComboTableCell) which overrides the TableCell class. This class defines the cell-factory of an editable combo-box which works perfectly if I use mouse clicks to traverse through the table. However, when i use keyboard tab totraverse, i face an issue.

Problem: When the first cell is selected using tab, the combo-box and its editor gets the focus. Hence user can directly start editing the cell.

The problem is that when I am done editing the first cell, I move to the next cell using the TAB button, however, the combo-box in the next cell does not get the focus and hence the user cannot directly start typing as in the case of first cell. Even the table does cell does not get the focus.

I have tried using the below code to get focus back to combo-box when I press tab

Platform.runLater(new Runnable() {
        @Override
        public void run() {
            comboBox.requestFocus();

            //I have also tried with comboBox.getEditor().requestFocus(); but still the issue persists
            comboBox.getEditor().selectAll();
        }
    });

Pls help me out with this issue.

1

There are 1 answers

0
Dhayal On BEST ANSWER

I have to face the same issue and i just found an workaround. If you make it as editable combo, it will resolve your issue.

ComboBox cb = new ComboBox(); cb.setEditable(true);