我在表格单元格中使用了TableCellRenderer多个自定义JFormattedTextField.我使用相同的组件TableCellEditor.现在我需要知道JFormattedTextField用户点击了什么,以及该字段中的位置(可以完成viewToModel).
使用自定义时TableCellEditor,Point从鼠标单击获取的唯一方法是使用自定义isCellEditable(EventObject e)方法CellEditor.在Point给出的父母坐标系统相同.
anEvent在调用组件坐标系中.
但是如何在点击的坐标上获得组件?我试过findComponentAt(Point p)但它会回来null给我.
这是我测试过的一些代码:
@Override
public boolean isCellEditable(EventObject e) {
if(e instanceof MouseEvent) {
MouseEvent ev = (MouseEvent)e;
Point p = ev.getPoint();
// gives strange values
Point p3 = editor.getLocation();
// x: 0 y: 0
Point tp = ((JTable)e.getSource()).getLocation();
// these returns null
Component c1 = renderer.findComponentAt(p);
Component c2 = editor.findComponentAt(p);
System.out.println("Click at …Run Code Online (Sandbox Code Playgroud)