-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,107
  • 18
  • 130
  • 305
Fisol Rasel
  • 199
  • 2
  • 4
  • 7

3 Answers3

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

  • toString returns "true" / "false"

  • more in the JTable tutorial

mKorbel
  • 109,107
  • 18
  • 130
  • 305
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
  • 200,320
  • 28
  • 229
  • 974
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,025
  • 1
  • 13
  • 9