Are there any methods which i want to zoom the view of the viewport but the location of the components inside does not change. The setting is that i have a big jpanel inside a jscrollpane in which i only want to only change the view into zoomed mode. the objects can be dragged and drop anywhere inside the panel so that is why it is important that its xy position remains.
here's my present zoom code, what i do is i use the graphics 2d scale to zoom the view. the problem is that the position is a mess. I also want to zoom it out so that the whole panel fits the jscrollpane.
//zoom in draw method using scale
g2.translate(zoomX, zoomY);
g2.scale(zoomScale, zoomScale);
g2.translate(-zoomX, -zoomY);
Im also thinking of manipulating the viewport. here is my viewport initialization. the 2000 by 1000 dimension is the panel and the 750 by 698 is the extentsize of my viewport. any suggestion on how will i zoom without messing the position of the components? Maybe moving the setviewposition is part of the solution?
view = new JViewport();
view.setViewSize(new Dimension(2000,1000));
view.setExtentSize(new Dimension(750,698));
view.setViewPosition(new Point(view.getExtentSize().width/2,view.getExtentSize().height/2));