Monday 15 September 2014

java - JTable, TableColumnModelListener detecting selected row -


What I want to accomplish is the following: if the user focuses the 5th column of a line in my JT (or By clicking on it or by pressing tab until it reaches the 5th cell), I show a dialogue. Then the result of the dialogue will be inserted into that cell, I need to know the row and column to access that cell.

The problem I am facing now is that, if I click on the cell before focusing on something else in the table, () returns 1, while getSelectedColumn () is correct Returns the column.

Question: How can I determine the selected row on the first click in the table. Or my first option is to make a big solution to handle that first click separately.

  New table column model listener () {. . . @ Override Public Empty Colored Conversation (Lists of Event Events) {System.out.println (getSelectedColumn ()); // This is correct System.out.println (getSelectedRow ()); // first click on JTable at 1}}    

The problem arises because The row and a trigger that changes the selection (both mousePressed fi) in both the first one, then changing the other (with no guarantee on the order) would be: Column selection is controlled by two unrelated models. Consequently, at the time of receiving notification on one, you can not know whether the other has already changed or not.

To solve, wrap your custom handling of notification in an inventor: After all this, it is guaranteed to be having all pending events are processed: @Override Public Zero columnSelectChanged (ListSelectionEvent e) {SwingUtilities.invokeLater (New Runnable) {@Override Public Zero Run} {println (table.getSelectedColumn ()); // This is the correct System First click on JTable}}; out.println (table.gate selectredo ()); }

No comments:

Post a Comment