删除位置渲染
原文: https://docs.oracle.com/javase/tutorial/uiswing/dnd/droplocation.html
这是一个更高级的主题,大多数人不需要担心它。但是,如果您有自定义组件,则需要自己处理放置位置渲染。
您可以注册以在dropLocation属性更改时收到通知。您将监听此更改并使用getDropLocation方法在组件的自定义渲染器或paintComponent方法中自行渲染放置位置。
以下是侦听dropLocation属性的示例:
class Repainter extends PropertyChangeListener {public void propertyChange(PropertyChangeEvent pce) {repaintDropLocation(pce.getOldValue());repaintDropLocation(pce.getNewValue());}}comp.addPropertyChangeListener("dropLocation", newRepainter());
以下是paintComponent方法的示例:
public void paintComponent(Graphics g) {super.paintComponent(g);DropLocation loc= getDropLocation();if (loc == null) {return;}renderPrettyIndicatorAt(loc);}
