简体   繁体   English

Jtable swing获取行数据

[英]Jtable swing get rows data

i have a little problems with getting rows data from a jTable : 从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);
    }    
}

the problem is that a always get all data from the table except the last row, i dont know wht . 问题是,总是从表中获取除最后一行之外的所有数据,我不知道wht。

Nothing wrong with the loop on first glance but looks like line two could be the culprit: 乍一看循环没有错,但看起来像第二行可能是罪魁祸首:

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

That is probably returning null as you proceed through the rows and subsequently causing the loop to skip via the continue call which occurs if username or password are null. 这可能在您继续执行行时返回null,并随后通过continue调用导致循环跳过,如果用户名或密码为空则会发生。 Change to: 改成:

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

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

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