JLabel或JTable单元格上的ActionListener [英] ActionListener on JLabel or JTable cell

查看:139
本文介绍了JLabel或JTable单元格上的ActionListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 JLabel [] [] 的JTable作为数据。现在我想检测双击JLabel或表格单元格(但仅在其中一列中)。如何在JLabel表格单元格上添加Action / MouseListener?

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 add an Action/MouseListener on JLabel respectively table cell?

推荐答案

如何:

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
    }
  }
});

这篇关于JLabel或JTable单元格上的ActionListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆