How to show focus to previous row in JTable

Viewed 22

I have made a Jtable to check duplicate values, As soon as I put something in a column and just click on another cell then the popup dialog shows up. after clicking OK on dialog, the focus goes to the cell I clicked, but I want the focus to be on the same cell where a duplicate popup occurs.

table1.getModel().addTableModelListener(tableModelChanged -> {
        ArrayList<String> nameList = new ArrayList<>();
        var rows = table1.getRowCount();
        for(int i=0;i<rows;i++) {
            var name = table1.getValueAt(i, 1).toString().toLowerCase();
            nameList.add(name);
        }
        if (languageService.checkDuplicates(nameList,rows)) {
            Messages.showErrorDialog("Duplicate Name is Present", "Duplicate Name");
        }
    });
0 Answers
Related