1
1

Is it possible to configure JGraphX to expand the size of the canvas when the user clicks and drags to the edge of the mxGraphComponent? Here's the use case:

\n
    \n
  1. User opens a graph that fits into the canvas so no vertical or horizontal scrollbars are present
  2. \n
  3. User clicks the mouse on right edge of the mxGraphComponent and drags to the right.
  4. \n
\n

The rubberband is displayed during the drag as expected and the rubberband stops at the edge of the component. Is there a way to allow the canvas to grow in the direction of the drag? So in this example, the right edge of the canvas would expand to accommodate the drag.

asked 09 Jun '11, 09:49

cgidwhite's gravatar image

cgidwhite
194829
accept rate: 66%

Some more information: If the scrollbars are present, the click/drag rubberbanding does grow the size of the canvas. This is only a problem when scrollbars are not present.

(09 Jun '11, 10:04) cgidwhite

Correction to the above comment, the click/drag of the rubberband when scrollbars are present doesn't grow the size of the canvas, it simply pans the canvas.

(13 Jun '11, 05:30) cgidwhite

Is the behavior above possible with JGraphX?

(01 Nov '11, 07:42) cgidwhite

This is currently not supported in Java. However, there is mxGraphControl.extendCanvas which can be called via mxGraphControl.scrollRectToVisible. I've added a autoScroll method in mxGraphHandler and called it in mxGraphHandler.mouseDragged (line 1054):

\n
protected void autoScroll(MouseEvent e, boolean extend)\n{\n  int border = 20;\n  Point translate = graphComponent.getGraphControl().getTranslate();\n  int tx = (e.getX() - border < 0) ? translate.x : 0;\n  int ty = (e.getY() - border < 0) ? translate.y : 0;\n\n  Rectangle rect = new Rectangle(e.getX() - tx, e.getY() - ty, 0, 0);\n  rect.grow(border, border);\n\n  this.graphComponent.getGraphControl().scrollRectToVisible(rect, extend);\n}\n
\n

This seems to work more or less...

link

answered 01 Nov '11, 08:19

Gaudenz's gravatar image

Gaudenz
80.1k1310
accept rate: 39%

edited 01 Nov '11, 08:43

I was implementing this as a custom subclass of mxGraphHandler but there is an issue with the mouseDragged() method referencing private instance variables. This prevents me from overriding the mouseDragged() method and adding the call-out you mention. I tried calling the super.mouseDragged() first but the first instance variable is null after the superclass implementation is finished (I was using that as a gate condition because the place where you specify above depends on the first instance var not being null).

(02 Nov '11, 06:55) cgidwhite

Are there any other suggestions on how to implement this behavior?

(15 Dec '11, 09:40) cgidwhite
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
×37
×10

Asked: 09 Jun '11, 09:49

Seen: 3,485 times

Last updated: 15 Dec '11, 09:40