I am dragging a cell from the palette into the graph component. While dragging every cell I am hovering is marked with a blue rectangle. Now I want to check (while dragging!) if the current hovered cell is a valid parent for the dragged cell.\

Example: Cell Type A can only be dropped on cell Type B, etc.

So I want to mark the hovered cell blue if it is a valid parent, otherwise red for example. So I checked the handler classes in com.mxgraph.swing.handler.*, but I don't know which handler does this hovering.

asked 31 Aug '11, 22:52

mkr_cursor's gravatar image

accept rate: 0%

edited 22 Apr '13, 07:47

David's gravatar image


Override mxGraph.getDropTarget or isValidDropTarget. We'll add accessors for the marker in mxGraphHandler, which is in charge of painting the highlight.


answered 01 Sep '11, 01:00

Gaudenz's gravatar image

accept rate: 39%

edited 01 Sep '11, 01:01

Thanks for your answer. I got my scenario working now. But I have a follow up question. Is there any chance to avoid dropping the cell if the marked cell is not a valid parent? Because when the parent is invalid the cell is added to the default parent of the graph. I tried to override mxGraph.getDefaultParent(), but it didn't work out.

(01 Sep '11, 05:34) mkr_cursor

Override mxGraphTransferHandler.importCells or mxGraphComponent.importCells.


answered 01 Sep '11, 06:05

Gaudenz's gravatar image

accept rate: 39%

As today, mxGraphTransferHandler.importCells or mxGraphComponent.importCells does not exists. There is only one importCells method under mxGraph prototype, but it never gets called while drag&dropping elements inside our diagram.

What I need to do is to avoid certain elements to be dropped inside the canvas (aka defaultParent).

(22 Apr '13, 07:37) juanghurtado

The question relate to the Java component, thus it is labelled "JGraphX"

(22 Apr '13, 07:40) David

You are right. So sorry. The first solution given on this thread was right for my Javascript, that's why I assumed it was about Javascript. Sorry again.

(22 Apr '13, 07:43) juanghurtado
Your answer
toggle preview

Follow this question

By Email:

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



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



Asked: 31 Aug '11, 22:52

Seen: 3,959 times

Last updated: 22 Apr '13, 07:47