我们可以倾斜一个JPanel吗? [英] Can we tilt a JPanel at an angle?

查看:84
本文介绍了我们可以倾斜一个JPanel吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JPanel中有图像.我想旋转图像.是否可以使用Graphics旋转JPanel,图像可旋转,是否出于好奇而可以旋转JPanel?

I have image inside the JPanel. I would like to rotate the image. Is it possible to rotate the JPanel using Graphics, Image is rotatable, Just out of curiosity is it possible to rotate JPanel ?

推荐答案

是的!这是可能的,而且也非常简单.我没有进行轮换,但在项目上做得非常成功,还完成了其他仿射转换(上下缩放整个GUI).我看不出为什么轮换应该有所不同.

Yes! This is possible and fairly straightforward too. I haven't done rotations but I have done other affine transformations (scaling the entire GUI up and down) very successfully on a project. I cannot see why rotations should be any different.

您可以在Graphics对象上设置转换,而不是尝试缩放每个组件.由于这是在所有要渲染的组件之间共享的,因此您可以免费"立即转换所有内容.重要的是要意识到变换只是一个渲染过程步骤...即所有组件仍然认为它们具有您在未变换的世界中所赋予的边界(位置+大小).这给我们带来了正确处理鼠标事件的挑战.为此,您只需在主面板前面添加一个玻璃窗格即可.此窗格收集所有鼠标事件,并对事件应用相反的转换,然后将事件向前发送给所有其他组件.

Instead of trying to scale each component use the fact that you can set a transformation on the Graphics object. Since this is shared between all components being rendered you get all things transformed at once "for free". It is important to realize that the transformation is only a rendering-process-step ... i.e. all components still believe they have the bounds (locations+sizes) which you gave them in the untransformed world. This leaves us with the challenge to deal with mouse-events correctly. To do this you simply add a glass-pane in front of your main-panel. This pane collects all mouse-events and apply a reverse of the transform on the event and then sends the event onward towards all other components.

从概念上讲非常简单!不过,我记得虽然需要一些调整才能使所有内容变得清晰.特别是在Java中渲染的文本(字体)未正确线性缩放(它以与字体大小相对应的离散步骤缩放)的事实在我的scale-affine-transformation-case中提出了最后一个挑战.也许您只旋转就不必担心.

Conceptually very simple! Still, I remember it took some tweaking to get it all crisp though. Especially the fact that rendered texts (fonts) in java are not correctly linearly scaled (it scales in discrete steps corresponding to font-sizes) imposed a final challenge in my scale-affine-transformation-case. Maybe you don't have to worry about that if you only rotate.

我从JXTransformer获得了灵感: http://www .java.net/blog/alexfromsun/archive/2006/07/jxtransformer_t.html

I got my inspiration from JXTransformer: http://www.java.net/blog/alexfromsun/archive/2006/07/jxtransformer_t.html

这篇关于我们可以倾斜一个JPanel吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆