线程中的异常" AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException:8> = 8
我怀疑它是因为它无法找到当前选定的组合框(位于第9行)...所以我该如何取消选择呢?
和uhm(旁边的问题)有没有办法同步这两个表? (因为我正在做的只是将值从一个表复制到另一个表)
编辑: 这是问题的一个示例,但是如果运行起来太麻烦我只是提供一个关于如何创建问题的屏幕截图...
http://oi58.tinypic.com/2qdap3s.jpg(对不起,我是新的,所以我不能直接在这里发布图片)
public class TableClass extends JFrame {
public TableClass() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
jScrollPane2 = new JScrollPane();
edittable = new JTable();
remove = new JButton();
edit = new JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
edittable.setModel(DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Table 1", "Table 2", "Table 3", "Table 4"
}
));
jScrollPane2.setViewportView(edittable);
remove.setText("Remove last row");
remove.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
removeActionPerformed(evt);
}
});
edit.setText("Edit");
edit.addActionListener(ActionListener() {
public void actionPerformed(ActionEvent evt) {
editActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 375, GroupLayout.PREFERRED_SIZE)
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(remove)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(edit)
.addGap(109, 109, 109))
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 95, GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(edit)
.addComponent(remove))
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}
private void editActionPerformed(ActionEvent evt) {
TableColumn column = edittable.getColumnModel ().getColumn ( 3 );
//I'm using a custom renderer from WebLAF
WebTableCellRenderer renderer = new WebTableCellRenderer ();
column.setCellRenderer ( renderer );
JComboBox comboBox = new JComboBox ();
comboBox.addItem ( "1" );
comboBox.addItem ( "2" );
comboBox.addItem ( "3" );
comboBox.addItem ( "4" );
column.setCellEditor ( new WebDefaultCellEditor ( comboBox ) );
}
private void removeActionPerformed(ActionEvent evt) {
DefaultTableModel model = (DefaultTableModel)edittable.getModel();
int rows = model.getRowCount();
model.removeRow(rows-1);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TableClass().setVisible(true);
}
});
}
private JTable edittable;
private JButton remove;
private JButton edit;
private JScrollPane jScrollPane2;
}