尝试在方法中从 Jtable 中提取数据,但一无所获
我遇到的问题是当我尝试通过创建一个方法并调用该方法来从表中查找数据时。该表似乎不存在,因为我收到 ArrayIndexOutOfBoundsException 异常。
下面是代码,模型是tableModel
。
// @Override
public void actionPerformed(ActionEvent arg0) {
String s = dropDown.getSelectedItem().toString();
if(s.equals("9 out of 11")) {
System.out.println(model.getValueAt(1, 1));
} else {
checkScores();
}
}
});
return panel;
}
public static void checkScores(){
Object o = model.getValueAt(1, 1);
int i = ((Integer) o).intValue();
System.out.println(i);
}
The problem I am having is when I am trying to find data from the table by making a method and calling that method. It seems that the table doesn't exist, as I am getting an ArrayIndexOutOfBoundsException
.
Below is the code, model is the tableModel
.
// @Override
public void actionPerformed(ActionEvent arg0) {
String s = dropDown.getSelectedItem().toString();
if(s.equals("9 out of 11")) {
System.out.println(model.getValueAt(1, 1));
} else {
checkScores();
}
}
});
return panel;
}
public static void checkScores(){
Object o = model.getValueAt(1, 1);
int i = ((Integer) o).intValue();
System.out.println(i);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有足够的信息来确定,但似乎在
TableModel
之前调用了ActionListener
完全建成。另外,验证所有 Swing 组件是否仅在 事件调度线程。There is not enough information to be certain, but it appears that the
ActionListener
is being called before theTableModel
is fully constructed. Also, verify that all Swing components are being constructed and manipulated only on the event dispatch thread.