How do I add mouseClicked event to a swing table?
- by Ayelet
Hi,
I am a new, terribly green user of Swing. I managed to create a table class using examples from java.sun tutorials, and I managed to load data dynamically into it. I want to be able to react to a click on a row by displaying a dialog box. How do I add the event Handler that will identify the selected row number?
The main function code:
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
MainWindow window = new MainWindow();
window.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
createAndShowGUI();
//...
and:
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("Data Table");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up data of the content pane.
TableClass mainTable = new TableClass(fh.getColNames(), fh.getTableContent());
mainTable.setOpaque(true);
frame.setContentPane(mainTable);
//Display the window.
frame.pack();
frame.setVisible(true);
}
Thank you