【发布时间】:2014-10-15 14:59:34
【问题描述】:
我想知道是否有人知道为什么 sun.swing.AccessibleMethod 从 JDK 8 中消失了,以及在 JDK 8 中是否有这个类的替代品?
我在任何地方都找不到任何相关信息。
我在自己的实现中使用这个类DropHandler。我使用sun.swing.AccessibleMethod 的代码 sn-p 如下所示:
private DropLocation getDropLocation(DropTargetEvent e)
{
DropLocation dropLocation = null;
if (this.component != null)
{
try
{
Point p = e instanceof DropTargetDragEvent ? ((DropTargetDragEvent)e).getLocation() : ((DropTargetDropEvent) e).getLocation();
AccessibleMethod method = new AccessibleMethod(JComponent.class,
"dropLocationForPoint",
Point.class);
dropLocation = (DropLocation) method.invokeNoChecked(this.component, p);
}
catch (NoSuchMethodException ex)
{
LOGGER.info(ex.getMessage());
}
}
return dropLocation;
}
【问题讨论】:
-
不知道为什么这个类在 JDK 8 中被删除了。不过,如果你读过the source code,它只是反射方法的一个包装器。您可以将此代码复制/粘贴到您的项目中的自定义类中,并使用此自定义类替换
sun.swing.AccessibleMethod。 -
感谢您的回答@LuiggiMendoza,是的,编写我自己的包装类是个好主意,但我希望有人知道为什么这个类被删除了,这很奇怪。
标签: java swing java-8 netbeans-platform