开发者

Click event on jTable -Java [duplicate]

开发者 https://www.devze.com 2023-04-03 09:05 出处:网络
This question already has answers here: ActionListener on JLabel or JTable cell (3 answers) 开发者_开发技巧
This question already has answers here: ActionListener on JLabel or JTable cell (3 answers) 开发者_开发技巧 Closed 10 years ago.

I have created a table in java in Netbeans and filled it with some data. Now I want to show some detail in a text area corresponding to the particular column in a row when I click on that cell. How can I find out using event listener that on which cell user has clicked.


Find the location of the click event and get the cell you are searching for:

jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
    @Override
    public void mouseClicked(java.awt.event.MouseEvent evt) {
        int row = jTable1.rowAtPoint(evt.getPoint());
        int col = jTable1.columnAtPoint(evt.getPoint());
        if (row >= 0 && col >= 0) {
            ......

        }
    }
});


JTable can listnening for selected TableCell (by mouseclick or from keyboard),you have to look for implemets ListSelectionListener, examples here or here

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号