Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Diagram which matches current window size or in ScrollPane? (Read 3561 times)
AR
Junior Member
**
Offline


I Love MindFusion!

Posts: 65
Joined: Jan 23rd, 2015
Diagram which matches current window size or in ScrollPane?
Apr 22nd, 2015 at 4:51pm
Print Post  
Is it possible to have the diagram automatically 'fill' the window it is displayed in? So that it changes size as the window changes size? And that any background image 'stretches' or 'fits' to the current window size?

Alternatively do you have an example of how to display a Diagram filling a ScrollPane? I can't see one in the 'samples' but I may have missed something.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Diagram which matches current window size or in ScrollPane?
Reply #1 - Apr 23rd, 2015 at 11:13am
Print Post  
Try handling the componentResized event to make Bounds as large as parent frame:

Code
Select All
public class TestFrame extends JFrame {
	private Diagram diag;
	private DiagramView view;

	public TestFrame() {

		diag = new Diagram();
		diag.setBounds(new Rectangle2D.Float(0, 0, 300, 300));

		view = new DiagramView(diag);

		this.addComponentListener(new ComponentAdapter() {
		    public void componentResized(ComponentEvent e) {
		    	Rectangle pixelSize = view.docToDevice(diag.getBounds());
		    	if (pixelSize.width < TestFrame.this.getWidth() ||
		    		pixelSize.height < TestFrame.this.getHeight())
		    	{
		    		pixelSize.width = Math.max(pixelSize.width, TestFrame.this.getWidth());
		    		pixelSize.height = Math.max(pixelSize.height, TestFrame.this.getHeight());
		    		diag.setBounds(view.deviceToDoc(pixelSize));
		    	}
		    }
		});
... 



If the diagram will stay as large as the frame, you could use the BackgroundImageAlign property to stretch or fit the image. Otherwise you would have to custom-draw the image from drawBackground event handler to align it relatively to currently visible part of the diagram.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
AR
Junior Member
**
Offline


I Love MindFusion!

Posts: 65
Joined: Jan 23rd, 2015
Re: Diagram which matches current window size or in ScrollPane?
Reply #2 - Apr 23rd, 2015 at 4:04pm
Print Post  
That works really nicely thanks.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint