Java Jtable swing获取行数据
我在从jTable获取行数据时遇到了一些小问题:Java Jtable swing获取行数据,java,swing,jtable,Java,Swing,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) {
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);
}
}
for(int i=0;i
问题是a总是从表中获取除最后一行之外的所有数据,我不知道是什么。循环乍一看没有问题,但看起来第二行可能是罪魁祸首:
...
username = TB_Accounts.getModel().getValueAt(i, i);
...
这可能是在继续执行行时返回null,然后通过continue
调用跳过循环,如果用户名或密码为null,则会发生该调用。改为:
...
username = TB_Accounts.getModel().getValueAt(i,0);
...
应该是:username=TB_Accounts.getModel().getValueAt(i,0)?是的,我找到了,谢谢::ps:如何设置线程解决??