简体   繁体   中英

Getting value of checkbox from jtable in java

我在从Java的jtable获取复选框的值时遇到问题,那就是当我通过此代码“ table.getvalue(0,1)”获取值时,我无法获取正确的值。

  • returns value from JTable contains JCheckBox represents Boolean value,

  • toString returns "true" / "false"

  • more in the JTable tutorial

作为一个具体示例,当我在此示例actionPerformed()方法中将以下行添加到循环中时,得到了预期的结果:

System.out.println((table.getValueAt(i, CHECK_COL)));

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;
                    }
                 }     
              }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM