user_777
user_777

Reputation: 805

mouseclick action event performs in wrong way in java

Here am using mouseClicked event to get data on the field while clicking on the table for that i used my code as below

scrollPane.addMouseListener(new MouseAdapter() {

        public void  mouseClicked(MouseEvent e) {

            int rowIndex= table.getSelectedRow();
            DefaultTableModel model=(DefaultTableModel) table.getModel();
            txt_Product_ID.setText(model.getValueAt(rowIndex,0).toString());
            txt_Product_Code.setText(model.getValueAt(rowIndex,1).toString());
            txt_Product_Name.setText(model.getValueAt(rowIndex,2).toString());
        }
    });

Here the problem is when i click on the row or column the data is not appearing on the corresponding fields but appearing when clicking on row or column and clicking on the remaining space available on the table.so double time clicking only producing the result.please help me to solve my problem

Upvotes: 0

Views: 40

Answers (1)

camickr
camickr

Reputation: 324128

scrollPane.addMouseListener(new MouseAdapter() {

Here the problem is when i click on the row or column the data is not appearing on the corresponding fields

Don't add the MouseListener to the scrollPane. The MouseListener should be added to the table, since that is the component you are clicking on.

Upvotes: 1

Related Questions