0

In my Jtable instance a column have the jComboBox , now what i want is to select the row and column of the cell once the value of selected jcombobox is changed.

If i use the actionPerformed event of the jcombobox, and get the jtable.getSelectedrow and column. System give me last selected row and column instead of current row and column.

Please guide me what to do .. thank you

private void jComboBoxActionPerformed(java.awt.event.ActionEvent evt) {                                                                  


            DefaultTableModel model = (DefaultTableModel) jTable.getModel();

            int selectedRow = jTable.getSelectedRow();
            int selectedColumn = jTable.getSelectedColumn();

            System.out.println("Row : " + selectedRow);
            System.out.println("Column : " + selectedColumn);
        } 
  • 1
    Possible duplicate of [Adding JCombobox in Jtable and Getting that Row and Column in Swing java](http://stackoverflow.com/questions/23421952/adding-jcombobox-in-jtable-and-getting-that-row-and-column-in-swing-java) – AxelH Dec 05 '16 at 10:52

1 Answers1

1

now what i want is to select the row and column of the cell once the value of selected jcombobox is changed.

Don't add an ActionListener to the combo box, that is not the way an editor of the table was designed to be used.

Instead you should be adding a TableModelListener to the TableModel of the JTable. An event will be generated whenever data is changed in the table. The event will contain the row/column of the cell that was changed.

For a working example check out: TableModelListener and multiple column validation

Community
  • 1
  • 1
camickr
  • 321,443
  • 19
  • 166
  • 288