放置位置渲染
这是一个更高级的主题,大多数人无需担心。但是,如果您有一个自定义组件,则需要处理自己呈现的放置位置。
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);
}