In my application i have a JPanel filled with Swing components. I have to zoom this JPanel within a JScrollPane.
I already wrote a JZoomPane, which has a paint method like
public void paint(Graphics g) {
if (zoomFactor != 1) {
Graphics2D g2 = (Graphics2D)g;
g2.scale(zoomFactor, zoomFactor);
}
super.paint(g);
}
There are two problems i don't know how to solve:
1. To manage the repainting, i know i have to write my own RepaintManager, but i don't know which part i have to customize.
2. I have to catch the MouseEvents and transform them against the zoom factor. But i can't use the GlassPane because i have to zoom only the part in the JScrollPane and not the rest of the application. I experimented a little bit with JLayeredPanes but couldn't get them to work.
Could anybody help me or, even better, send me some sample code.
Thanks,
Oliver
Many thanks to you. i tried this solution but it's somewhat slow.is there is a faster solution....
By waelatef
Hi all,I've created a customized JTable and component editors/renderers. I also created a class that...
By amlandis
Hi,Does any one worked on Changing the layout Constraints dynamically before ?, If so Can you explai...
By chekks
Hi,I am trying to change the colors of an already-on-the-screen JTree on the fly. The following code...
By chatterbox453732a
Hello All, I've got a small problem with setting the focus in a JOptionPane. My JOptionPane consists...
By endolin, 1 Comments
Hi all,i have an object from java.awt.Image and want to convert it to java.awt.image.BufferedImage i...
By ranxeoa, 1 Comments
Hi! How do I override the default functionality of JOptionPane from Space key to Enter key when OK o...
By 771003a, 2 Comments
Is there any way to change those texts in buttons? Eg. I need to have something different on cancel-...
By meev, 1 Comments
Hi all,i have a java.awt.Image object and want to convert it to java.awt.image.BufferedImage object....
By waelatef, 2 Comments
Something like this:
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
if (scale != 1.0) {
AffineTransform af = new AffineTransform();
af.scale(scale, scale);
oldTransform = g2d.getTransform();
g2d.transform(af);
}
super.paint(g)
if (scale != 1) {
g2d.setTransform(oldTransform);
}
}
and you have to change size of your panel according to new size.
mouse motion event returns x and y coordinates.
e.getX();
e.getY();
newX=scale*e.getX();
newY=scale*e.getY();
best regards
Stas
stanislavla | Sat, 07 Jul 2007 16:25:00 GMT |
1. The problem is not the scaling itself. I get the panel painted in the correct scaled size when it appears for the first time. But when i scroll the panel, the contained components repaint themselves at the original unscaled position in normal size. I think therefore i have to subclass the RepaintManager (somewhere i read something about it).
2. Scaling the MouseEvents isn't the problem also. The problem is to catch the MouseEvents without using the glasspane, because i only want to scale parts of my application (i.e. the content of the JScrollPane).
schlenzkaa | Sat, 07 Jul 2007 16:25:00 GMT |
You will need to change the size and locations of your child components when you adjust the scale on your main panel. I have been trying to do this, but currently it has been unsuccessful.
jon_ixa | Sat, 07 Jul 2007 16:25:00 GMT |