繁体   English   中英

Jtable swing获取行数据

[英]Jtable swing get rows data

从jTable获取行数据时遇到一些问题:

for (int i = 0; i < TB_Accounts.getRowCount(); i++) {
    username = TB_Accounts.getModel().getValueAt(i, i);
    password = TB_Accounts.getModel().getValueAt(i, 1);

    if (username == null || password == null) {
        continue;
    }

    System.out.println("userName : " + username);
    System.out.println("password : " + password);

    if (!username.toString().equalsIgnoreCase("") && !password.toString().equalsIgnoreCase((""))) {
        accouts.add(new Account(username.toString(), password.toString()));

        System.out.println("in :: userName : " + username);
        System.out.println("in :: password : " + password);
    }    
}

问题是,总是从表中获取除最后一行之外的所有数据,我不知道wht。

乍一看循环没有错,但看起来像第二行可能是罪魁祸首:

...
username = TB_Accounts.getModel().getValueAt(i, i);
...

这可能在您继续执行行时返回null,并随后通过continue调用导致循环跳过,如果用户名或密码为空则会发生。 改成:

...
username = TB_Accounts.getModel().getValueAt(i,0);
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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