ActionListener on JLabel or JTable cell

后端 未结 2 1368
眼角桃花
眼角桃花 2020-12-03 03:04

I have a JTable with JLabel[][] as data. Now I want to detect a double click on either the JLabel or a table cell (but only in one of the columns). How can I ad

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 03:47

    How about:

    table.addMouseListener(new MouseAdapter() {
      public void mouseClicked(MouseEvent e) {
        if (e.getClickCount() == 2) {
          JTable target = (JTable)e.getSource();
          int row = target.getSelectedRow();
          int column = target.getSelectedColumn();
          // do some action if appropriate column
        }
      }
    });
    

提交回复
热议问题