Reputation: 63
I have a jtable and I want the user to fill its cells then i get what he wrote! the problem is when i try getValueAt(row index,col index ) the programe give me null , and i am sure that the cell i choose has a value . following show how i create the table
String s = JOptionPane.showInputDialog(null, "Enter number of rows");
int row = Integer.parseInt(s);
Vector v = new Vector();
v.add("URL");
DefaultTableModel Dm = new DefaultTableModel(v, row);
jTable1.setModel(Dm);
Upvotes: 1
Views: 6646
Reputation: 5575
I suppose that you use the default model. You can obtain the selected cell and display the content by writing something like this :
int i = jTable1.getSelectedRow();
int j = jTable1.getSelectedColumn();
JOptionPane.showMessageDialog(null, jTable1.getModel().getValueAt(i, j));
Or if you want , use getRowCount()
and getColumnCount()
to get other cells value. But all that explanation depends on one question:
Upvotes: 2