Salut,
Je n'ai jamais eu le besoin de le faire; regarde si le fait de remplacer les noms de toutes les colonnes te va:
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class Sample extends JFrame {
private JTable table;
private static final long serialVersionUID = 1L;
public static void main(String args[]) {
try {
Sample frame = new Sample();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
public Sample() {
super();
setBounds(100, 100, 500, 375);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JScrollPane scrollPane = new JScrollPane();
getContentPane().add(scrollPane, BorderLayout.CENTER);
table = new JTable();
scrollPane.setViewportView(table);
String[] cols = new String[] { "col 1", "col 2", "col 3" };
String data[][] = new String[][] {};
DefaultTableModel model = new DefaultTableModel(data, cols);
table.setModel(model);
final JPanel panel = new JPanel();
final FlowLayout flowLayout = new FlowLayout();
flowLayout.setAlignment(FlowLayout.RIGHT);
panel.setLayout(flowLayout);
getContentPane().add(panel, BorderLayout.SOUTH);
final JButton renameColumnButton = new JButton();
renameColumnButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Will rename the first table column
DefaultTableModel model = (DefaultTableModel) getTable().getModel();
model.setColumnIdentifiers(new String[] { "new col 1", "new col 2", "new col 3" });
}
});
renameColumnButton.setText("Rename column");
panel.add(renameColumnButton);
//
}
protected JTable getTable() {
return table;
}
}
++