I have what I hope is a simple question. I've looked in the API and searched this forum but can't quite get my head wrapped around it.

What method is available in JGraphX to find one mxCell in a mxGraph based upon the id provided when the cell was created?

If a direct query is not possible, do I have to iterate over all cells associated with a parent and find the one that matches the id I provide?

In this case I'm providing the optional Id, not using the default generated by JGraphX. I'll always know the Id when querying the mxGraph data.

In this application the number of vertices and edges is quite large, 10,000's or more. I'm trying to avoid excessive computing wherever possible. Hence I don't want to iterate over a lot of child cells to locate the one cell I need, if I can avoid it.

This question is marked "community wiki".

asked 03 Jul '11, 17:53

George%20Shannon's gravatar image

George Shannon
0111
accept rate: 0%

edited 18 Dec '12, 09:11

David's gravatar image

David
4.9k21831


mxGraphModel.getCell(myid); where "my id" is the cell id, should work fine!

link

answered 17 Dec '12, 08:45

Kalkidan%20Ferede's gravatar image

Kalkidan Ferede
262
accept rate: 50%

Did you try graph.getModel().getCell(id)

link

answered 06 Jul '11, 10:07

mangledaxle's gravatar image

mangledaxle
3114
accept rate: 0%

There is no method getCell(String id) in the graph model. I also need a function to access an node by its unique id.

(12 Jul '11, 08:26) thatstraight

There is that function in mxGraphModel class. But the graph only returns the interface mxIGraphModel, so that you have to downcast to the implementation class.

mxCell myCell = (mxCell) ((mxGraphModel)graph.getModel()).getCell(myId);

(12 Jul '11, 08:55) thatstraight

i assumed you were using javascript which getCell method is available. Seems like a bug that the getCell(id) method is not exposed in the java mxIGraphModel interface. Maybe there's another way in java to get a cell using its unique id.

(12 Jul '11, 09:14) mangledaxle
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×194
×66
×45
×5

Asked: 03 Jul '11, 17:53

Seen: 10,403 times

Last updated: 18 Dec '12, 09:14