2012-03-13 157 views
0

enter image description here添加列的ActionListener JTable中

大家好..我 又需要一些幫助。 :)

如何做到這一點?當我點擊列t1時,必須彈出另一個表單來解釋列t1發生了什麼,例如,在時間1時,指令1處於獲取階段。然後,當我點擊naman t2列時,指令2處於提取階段,指令1處於解碼階段,等等。

預先感謝您。我真的需要你的幫助.. 問候.. :)

回答

2

您需要添加以下代碼塊,這將上雙擊打開

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

    }); 

的對話框。

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

} 
+0

感謝你的代碼,我得到它.. – Celine 2012-03-13 14:00:58

+0

非常歡迎你!。 – 2012-03-13 14:01:49

0

Generaly它應該是這樣的

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

你得到的柱而出事件,然後做你想做的事情是什麼。

+0

不是來自這個問題太明顯 - 但它的左右搖擺:-) – kleopatra 2012-03-13 15:13:22