I have a JPanel that contains a JTable and a JButton. The desired functionality is: - for every row of the table the user clicks, a second table appears in the panel - if the button is clicked, a popup table appears
For the table I have implemented a mouse listener like this:
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int row = table.getSelectedRow();
int col = table.getSelectedColumn();
System.out.println("Table: " + row + " " + col);
// perform some table processing here
// the new table to appear is data1
// update the content of the panel dataP
dataP.removeAll();
dataP.setLayout(new BorderLayout());
dataP.add(new JScrollPane(data1), BorderLayout.NORTH);
dataP.updateUI();
}
}
});
The listener works fine until I click the button and the popup table appears. After doing this, if I click on the initial JTable I always get that the selected row/column is -1,-1. Why is this happening? Since the table and the button are two separate components (also placed in different panels), how is it possible for the one to affect the other? Thanks in advance!