简体   繁体   English

在jtable中添加column的actionlistener

[英]Adding actionlistener of column in a jtable

在此输入图像描述

Hi everyone.. I need some help again. 大家好..我还需要一些帮助。 :) :)

How to do this? 这个怎么做? When I click the column t1, another form must pop-up explaining what happens to column t1, say, at time 1, Instruction 1 is in fetch stage. 当我单击列t1时,必须弹出另一个表单,说明列t1会发生什么,比如说,在时间1,指令1处于获取阶段。 Then, when I click naman t2 column, Instruction 2 is in fetch stage and Instruction 1 is in Decode stage., so on and so forth. 然后,当我点击naman t2列时,指令2处于提取阶段,指令1处于解码阶段。依此类推。

Thank you in advance. 先感谢您。 I really need your help.. Regards.. :) 我真的需要你的帮助..问候.. :)

You need to add following chunk of code, 你需要添加以下代码块,

    table.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            // This is for double click event on anywhere on JTable
            if (e.getClickCount() == 2) {
                JTable target = (JTable) e.getSource();
                int row = target.getSelectedRow();
                int column = target.getSelectedColumn();
               // you can play more here to get that cell value and all
                new DialogYouWantToOpen(row, Column);
            }
        }

    });

A Dialog which will be opened on double click. 双击打开的对话框。

class DialogYouWantToOpen extends JDialog{
       JLabel testLabel = new JLable();
       public DialogYouWantToOpen(int row, int column){
         setSize(200,200)
         setLayout(new FlowLayout());
         testLabel.setText("User double clicked at row "+row+" and column "+ column);
         add(testLabel);
       }

}   

Generaly it should go something like this 通常它应该是这样的

Listener listener = new Listener() {
  public void handleEvent(Event e) {
    TableColumn column = (TableColumn) e.widget;
    System.out.println(column);
  }
};

you get the column out of event and then do what you want with it. 你从事件中得到列,然后用它做你想做的事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM