-1

I have a problem to get value of checkbox from jtable in java, that is when i get value by this code "table.getvalue(0,1)" then i can not get the right value.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Fisol Rasel
  • 359
  • 2
  • 5
  • 7

3 Answers3

3
  • returns value from JTable contains JCheckBox represents Boolean value,

  • toString returns "true" / "false"

  • more in the JTable tutorial

mKorbel
  • 109,525
  • 20
  • 134
  • 319
3

As a concrete example, I got the expected result when I added the following line to the loop in the actionPerformed() method of this example:

System.out.println((table.getValueAt(i, CHECK_COL)));
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
3

JTable get cehckbox value when check box is checked:-

table.getModel().addTableModelListener(new TableModelListener() {
              @Override
              public void tableChanged(TableModelEvent e) {
                  for(int i=0;i<table.getModel().getRowCount();i++)
                  {
                    if ((Boolean) table.getModel().getValueAt(i,0))
                    {  
                      System.out.println(">\t"+table.getSelectedRow());
                      break;
                    }
                 }     
              }
    });
Krishnakant Kadam
  • 3,225
  • 1
  • 14
  • 9