我搜索了在jtable中添加按鈕的教程,並從http://tips4java.wordpress.com/2009/07/12/table-button-column/找到了一個類文件在哪裏設置按鈕的標籤?將按鈕添加到jtable
[code]
private void createTable(){
model = new DefaultTableModel();
editorTable.setModel(model);
model.addColumn("COL1");
model.addColumn("COL2");
model.addColumn("ADD");
model.addColumn("DELETE");
model.addRow(new Object[]{"DATA1", "DATA2"});
Action delete = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
editorTable = (JTable) e.getSource();
int modelRow = Integer.valueOf(e.getActionCommand());
((DefaultTableModel) editorTable.getModel()).removeRow(modelRow);
}
};
ButtonColumn bc = new ButtonColumn(editorTable, delete, 3);
bc.setMnemonic(KeyEvent.VK_D);
}
[/code]
看看這裏:http://stackoverflow.com/questions/1475543/how-to-add-button-in-a-row-of-jtable-in-swing- java – MByD 2012-02-17 01:21:29
你檢查了關於JTable的oracle java教程:http://docs.oracle.com/javase/tutorial/uiswing/components/table.html檢查Renderer和編輯器 – asela38 2012-02-17 01:23:39
Binyamin,謝謝你的迴應,我實現了這個類,它工作正常,但我沒有找到在哪裏添加按鈕的標籤。 – FirmView 2012-02-17 01:28:18