我有一堆代碼使用Jtable在網格中顯示數據。我需要捕獲鼠標雙擊事件。但是有些這個簡單的代碼是如何在網格的Header上工作的,而不是在那個網格的行上工作。任何線索?還有一點,網格也是可編輯的。鼠標點擊JTable
謝謝。
問候。 Manish
我有一堆代碼使用Jtable在網格中顯示數據。我需要捕獲鼠標雙擊事件。但是有些這個簡單的代碼是如何在網格的Header上工作的,而不是在那個網格的行上工作。任何線索?還有一點,網格也是可編輯的。鼠標點擊JTable
謝謝。
問候。 Manish
你的一些代碼會有幫助。你在做類似的事嗎?
table.getTableHeader().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent event) {
if (e.getClickCount() == 2 && !e.isConsumed()) {
e.consume();
// handle double click here
}
});
感謝您的回覆,代碼在不可編輯的行上工作正常。但我怎麼能做同樣的可編輯行?該 – itcmanish 2012-01-13 13:43:22
你可以做到這一點作爲
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
*這個簡單的代碼*:哪個簡單的代碼? – 2012-01-13 07:41:51
交叉點https://forums.oracle.com/forums/thread.jspa?threadID=2332433&tstart=0 – mKorbel 2012-01-13 08:52:08
你是指「任何線索」?你昨天在交叉發佈的問題中給出了這種行爲的原因。 – camickr 2012-01-13 17:16:35