Is there a method to determine if two vertices are connected in JgraphX? The method isConnectable()
only returns true if the vertex is connected.
Asked
Active
Viewed 724 times
1 Answers
0
You can check it by checking the edges. In this example, being cell1 the first cell you have and cell2 the cell you want to check if its connected with cell1.
for (int i = 0; i < cell1.getEdgeCount(); i++) {
mxCell source = ((mxCell) cell1.getEdgeAt(i)).getSource();
mxCell target = ((mxCell) cell1.getEdgeAt(i)).getTarget();
if (source == cell2 || target == cell2)
return true;
else
return false;
}
You need to check both source and target 'cause you can't be sure if cell1 will be the source or the target in that iteration. This way, you iterate every cell that is connected to cell1 and checks if it is equal to a second cell.

Fagundes
- 119
- 10
-
Is the `==` operator appropriate here or should the `equals()` method be used instead? – entpnerd Apr 11 '16 at 21:01
-
@entpnerd You should use `==`. I'm not completely sure, but I guess the `.equals()` method can only be implemented in objects that extends the _class_ Object. From what I know, mxCell does not extends it (but you should check it). Anyway, basically you should use `.equals()` to compare Strings, and `==` to compare other objects. Take a look in this article, it will definitely explain better than I do http://www.programmerinterview.com/index.php/java-questions/java-whats-the-difference-between-equals-and/ – Fagundes Apr 12 '16 at 01:35