1 package edu.jiangxin.apktoolbox.swing.treetable; 2 3 import java.awt.Component; 4 import java.awt.event.MouseEvent; 5 import java.util.EventObject; 6 7 import javax.swing.AbstractCellEditor; 8 import javax.swing.JTable; 9 import javax.swing.JTree; 10 import javax.swing.table.TableCellEditor; 11 12 public class MyTreeTableCellEditor extends AbstractCellEditor implements TableCellEditor { 13 14 private JTree tree; 15 private JTable table; 16 17 public MyTreeTableCellEditor(JTree tree, JTable table) { 18 this.tree = tree; 19 this.table = table; 20 } 21 22 public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int r, int c) { 23 return tree; 24 } 25 26 public boolean isCellEditable(EventObject e) { 27 if (e instanceof MouseEvent) { 28 int colunm1 = 0; 29 MouseEvent me = (MouseEvent) e; 30 int doubleClick = 2; 31 MouseEvent newME = new MouseEvent(tree, me.getID(), me.getWhen(), me.getModifiers(), me.getX() - table.getCellRect(0, colunm1, true).x, me.getY(), doubleClick, me.isPopupTrigger()); 32 tree.dispatchEvent(newME); 33 } 34 return false; 35 } 36 37 @Override 38 public Object getCellEditorValue() { 39 return null; 40 } 41 42 }