[英]Zoom JPanel in Java Swing
I have an existing Java Swing
application. 我有一个现有的
Java Swing
应用程序。 In the middle of the application is a single JPanel
which I want to be able to zoom in and out
of. 在应用程序的中间是一个
JPanel
,我希望能够zoom in and out
。 The JPanel
has a number of JComponents
on it (mostly other JPanels
and JLabels
). JPanel
上有许多JComponents
(主要是其他JPanels
和JLabels
)。
Also mouse
position will need to be adjusted appropriately as well - so mouseevents
need to remain same even after the JPanel
has been zoomed. 此外
mouse
位置需要进行适当的调整,以及-所以mouseevents
需要保持相同的偶数后JPanel
已被放大。 As such simply changing the paint
methods of each component
doesn't seem plausible. 因此,简单地改变每个
component
的paint
方法似乎不合理。
EDIT: 编辑:
OK i kind of got it working using the MagnifierUI
class
with some minor edits. 好吧,我有点使用
MagnifierUI
class
进行一些小编辑。 However the magnified panel I create has the wrong mouseevents
- ie the panel is scaled, mouseevents
are not. 然而,放大板创建有错误的
mouseevents
-即面板进行缩放, mouseevents
都没有。
This is just a scetch: 这只是一个问题:
JPanel
keep track of an AffineTransform which represents the scale factor (see AffineTransform.scale(double,double)
, JPanel
密切跟踪的AffineTransform代表比例因子(见AffineTransform.scale(double,double)
, paint
method of your JPanel
: before calling super.paint
apply the affine transformation to your Graphics2D
object (cast from the parameter of the paint
method) by calling Graphics2D.setTransform(AffineTransform)
, call super.paint
afterwards JPanel
的paint
方法:在调用super.paint
之前,通过调用Graphics2D.setTransform(AffineTransform)
将仿射变换应用于Graphics2D
对象(从paint
方法的参数super.paint
Graphics2D.setTransform(AffineTransform)
,然后调用super.paint
processMouseEvent
, processMouseMotionEvent
and processMouseWheelEvent
, apply the affine transformation to the coordinates of their mouse event parameter ( AffineTransform.transform(java.awt.geom.Point2D,java.awt.geom.Point2D)
), call respective super
-method afterwards. processMouseEvent
, processMouseMotionEvent
和processMouseWheelEvent
,将仿射变换应用于其鼠标事件参数的坐标( AffineTransform.transform(java.awt.geom.Point2D,java.awt.geom.Point2D)
),之后调用相应的super
方法。 Hope this helps. 希望这可以帮助。
试试SwingUtilities.convertPoint(source,point,destination);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.