java - jTable function getSelectedRow(), getSelectedColumn() returning -1 -
I'm new to Java programming I need to get the index of the selected column and row I am both for the column and line -1 is getting the selected index. I have searched for a solution, but I could not find anything satisfactory.
My code is the following:
Private Waste DelayPart Button Actioned (java.awt.event.ActionEvent evt) {Default Table Model Table Model = (Default Table Model) . Product DisableableGetModel (); JTable table = new JTable (tablemodel); Int selectedRoundEx = table.getSelectedRow (); Int selectColIndex = table.getSelectedColumn (); System.out.println (SelectedRoundX); Println (selectedColIndex); }
In your code you create a new jetty but you do not add this component Thus, it will never be visible to any container and no row, nor can the column be ever chosen.
Now, while we can add components in the swing dynamically, we have seen top level containers (in this case) when you start your components (do not forget the scroll pane) The table should be taken and whatever you have to do after pressing the button.
On the other hand, I'm not sure what you are trying to achieve. I mean that you already have a table named productDisplaTable
if you selected in that table If you want to print the row and column, make a little change:
Remove Private Zero PrintButton Actioned (java.awt.event.ActionEvent evt) {// DefaultTableModel tableModel = (DefaultTableModel) This.productDisplaTable .getModel (); // JTable table = new JTable (table model); Int selectedRoindx = this.productDisplaTable.getSelectedRow (); Int selectColIndex = this.productDisplaTable.getSelectedColumn (); System.out.println (SelectedRoundX); Println (selectedColIndex); }
Comments
Post a Comment