I am using checkboxes in JTable
which itsef is part of JPanel
. Initially I was using JOptionPane
and on clicking OK button I was getting value but now I added JPanel
in a JFrame
. When I click X
sign on top right it is not retrieving value of clicked Checkboxes but able to fetch values of other columns. Code snippet given below:
DefaultTableModel dtm = new DefaultTableModel(rowData, columnNames)
{
};
for (int i = 0; i < records.size(); i++)
{
// System.out.println(records.get(i));
singleRecord = records.get(i).toString().split("%");
Pages = singleRecord[0].toString();
BKey= singleRecord[1].toString();
Title = singleRecord[2].toString();
Author = singleRecord[3].toString();
TimeStamp = singleRecord[4].toString();
dtm.addRow(new Object[] { Boolean.FALSE ,Pages,BKey,Title,Author,TimeStamp});
}
table = new javax.swing.JTable(dtm)
{
public boolean isCellEditable(int row,int column)
{
/*if(column == 0)
return true;
else
return false;
*
*/
return(column < 2);
}
};
for (int i = 0; i < table.getRowCount(); i++)
{
System.out.println(table.getValueAt(i,1).toString());
boolean isChecked = (Boolean) table.getValueAt(i,0);//always return false
if (isChecked)
{
System.out.println("checked ");
Ids+=table.getValueAt(i,2).toString()+"%";
}
}