2012-01-13 196 views
0

我有一堆代码使用Jtable在网格中显示数据。我需要捕获鼠标双击事件。但是有些这个简单的代码是如何在网格的Header上工作的,而不是在那个网格的行上工作。任何线索?还有一点,网格也是可编辑的。鼠标点击JTable

谢谢。

问候。 Manish

+3

*这个简单的代码*:哪个简单的代码? – 2012-01-13 07:41:51

+1

交叉点https://forums.oracle.com/forums/thread.jspa?threadID=2332433&tstart=0 – mKorbel 2012-01-13 08:52:08

+1

你是指“任何线索”?你昨天在交叉发布的问题中给出了这种行为的原因。 – camickr 2012-01-13 17:16:35

回答

1

你的一些代码会有帮助。你在做类似的事吗?

table.getTableHeader().addMouseListener(new MouseAdapter() { 

    @Override 
    public void mouseClicked(MouseEvent event) { 
     if (e.getClickCount() == 2 && !e.isConsumed()) { 
     e.consume(); 
     // handle double click here 
    } 

}); 
+0

感谢您的回复,代码在不可编辑的行上工作正常。但我怎么能做同样的可编辑行?该 – itcmanish 2012-01-13 13:43:22

0

你可以做到这一点作为

class ButtonEditor extends DefaultCellEditor { 
    protected JButton button; 

    private String label; 

    private boolean isPushed; 

    public ButtonEditor(JCheckBox checkBox) { 
    super(checkBox); 
    button = new JButton(); 
    button.setOpaque(true); 
    button.addActionListener(new ActionListener() { 
     public void actionPerformed(ActionEvent e) { 
     fireEditingStopped(); 
     } 
    }); 
    } 

这里可以提供任何组件,而不是按钮。 参考full example