How do I add mouseClicked event to a swing table?
        Posted  
        
            by Ayelet
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Ayelet
        
        
        
        Published on 2010-05-07T12:44:45Z
        Indexed on 
            2010/05/07
            12:48 UTC
        
        
        Read the original article
        Hit count: 306
        
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
© Stack Overflow or respective owner