Java 如何从表模型中获取所选行?
如何从表模型中获取所选行? 我试过以下方法Java 如何从表模型中获取所选行?,java,swing,jtable,tablemodel,indexoutofboundsexception,Java,Swing,Jtable,Tablemodel,Indexoutofboundsexception,如何从表模型中获取所选行? 我试过以下方法 checkBoxes[t].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int index = -1; for (int i = 0; i < checkBoxes.length; i++) { if (checkBoxes[i] == e.getSource()) {
checkBoxes[t].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int index = -1;
for (int i = 0; i < checkBoxes.length; i++) {
if (checkBoxes[i] == e.getSource()) {
String Status=null ;
DbUtility ViewAbsenties=new DbUtility();
ViewAbsenties.loadDriver();
ViewAbsenties.connect();
TableModel tm;
tm = table3.getModel();
if (checkBoxes[i].isSelected() == true) {
Status =(String) tm.getValueAt(i,8);
System.out.println("Status : " + Status );
}
}
}
}
}
- 我们的观点可能是,你必须这样做
- 以零开始的数组(
)是getValue(0,0
中的1st.row
)1st.column
- 必须正确设置或确定所有选定行
- 我们的观点可能是,你必须这样做
- 以零开始的数组(
)是getValue(0,0
中的1st.row
)1st.column
- 必须正确设置或确定所有选定行
请对代码块使用一致的逻辑缩进。错误表明您尝试访问的行不存在。您的表是否至少有9列?您是否尝试记录您认为对象位于哪一行,并根据您对模型的解释验证这一点?此问题与其他问题有关(选择是复选框,而不是表格选择,并查找值而不是索引)但是一些查看标题的人可能希望找到这样一个结果:请对代码块使用一致的逻辑缩进。您的错误表明您尝试访问的行不存在。您的表是否至少有9列?您是否尝试记录您认为对象位于哪一行,并对照您对模型的解释进行验证?这个问题是关于一些不同的内容(选择是复选框,而不是表格选择,并寻找值而不是索引),但一些查看标题的人可能希望找到以下内容:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1 >= 1
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableModel.getValueAt(Unknown Source)
at EmployeeLeave$10$1.actionPerformed(EmployeeLeave.java:490)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.JToggleButton$ToggleButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)