2 réponses
KX
Messages postés
16753
Date d'inscription
samedi 31 mai 2008
Statut
Modérateur
Dernière intervention
25 novembre 2024
3 020
1 mars 2013 à 17:56
1 mars 2013 à 17:56
Si j'ai bien compris ce que tu veux, tu devrais regarder How to Write a List Selection Listener. Exemple :
import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; public class Test { public static void main(String[] args) { String[] header = { "A", "B"}; String[][] data = {{"a0","b0"},{"a1","b1"},{"a2","b2"},{"a3","b3"},{"a4","b4"},{"a5","b5"}}; JTable table = new JTable(data,header); ListSelectionModel selection = table.getSelectionModel(); selection.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { System.out.println(e); } }); JFrame frame = new JFrame(); frame.add(new JScrollPane(table)); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }