简体   繁体   中英

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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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