Disabling Dynamic Connections

I have been going through the user guide and nothing has popped out at me yet. I have a graph which contains connections using JGoIconicNode objects (good so far). However, if the user clicks a certain spot on the node a link/connection is created to the closest node. How can I disable/prevent new connections/link from being made on the graph?

Yes, you are seeing the effects of PortGravity. PortGravity determines the minimum distance at which a link will snap to a port. It is intended to make it easier for users to interactively make connections, but if ports are too close to each other, a single click on the port can create a link to the nearby port.
Try calling JGoView.setDefaultPortGravity(int gravity) with a smaller value. The default is 100. Alternatively, you may want to adjust your autolyout parameters so that nodes (and their ports) are a little farther apart.

I’m wondering if the poster isn’t just asking how to disable user-drawn links or relinking.

First, if JGoDocument.isModifiable() is false, users should not be able to draw new links or relink existing links.

Second, you can call JGoPort.setValidSource(false) and setValidDestination(false) to prevent users from starting to draw a new link from or to a particular port.

Third, you can call JGoLink.setRelinkable(false) if you don’t want users to reconnect an existing link.

Fourth, you can override JGoView.pickPort to return null when you don’t want users to draw new links. This might be preferable to finding all of the ports and setting isValidSource/isValidDestination on each, if you expect the ability to change dynamically based on conditions/modes.

Thanks all for the information. Walter, you hit the nail on the head. Thank you much!