圆形 JPanel 摆动
我试图在我的 gui 中显示一个圆形对象,该圆形对象应该包含一些标签,因此我认为圆形对象应该扩展 JPanel。有谁知道如何制作一个圆形的JPanel?或者至少有一个 JPanel 绘制一个椭圆形并将一些 JLable 放置在椭圆形的中心?
谢谢
I am trying to display a circular object in my gui, the circular object should contain a few labels therefore I thought the circle object should extend JPanel. Does anyone know how to make a circular JPanel? Or at least a JPanel which paints an oval and places a few JLables in the centre of the oval?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要绘制圆形,请子类化
JPanel
并覆盖paintComponent
:如下所示:
alt text http://img246.imageshack.us/img246/3708/so2343233.png
要放置标签,您可以使用
GridBagLayout
,希望这就是您想要的:替代文本 http://img694.imageshack.us/img694/4013/so23432332.png
To paint a circle, subclass
JPanel
and overridepaintComponent
:Looks like this:
alt text http://img246.imageshack.us/img246/3708/so2343233.png
To place the labels, you could use
GridBagLayout
, hope that's what you want:alt text http://img694.imageshack.us/img694/4013/so23432332.png
在 O'Reilly 的《Swing Hacks》一书中,有一个针对透明和动画窗口的 hack #41。源代码可以从http://examples.oreilly.com/9780596009076/下载
In the book Swing Hacks from O'Reilly there is a hack for transparent and animated windows #41. The source code can be downloaded from http://examples.oreilly.com/9780596009076/