圆形 JSlider?
JSlider 默认情况下采用直线形状。我们可以把 JSlider 做成一个类似速度计的圆圈或者带有读数的圆圈吗?
如果有人做过类似的任务...请分享代码...
谢谢
A JSlider by default takes a straight line shape. Can we make JSlider a circle resembling like speed-o-meter or circle with reading?
If anyone has done something similar to this task... Please share the code...
Thank You
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
JFreeChart 有一个
DialPlot
这可能会给您一些关于如何进行渲染的想法。
JFreeChart has a
DialPlot
that might give you some ideas on how to do the rendering.没有默认的方法可以做到这一点。但是,如果您正在创建自定义组件,听起来您想要某种可以抓取和调整的转盘,而不是一个圆形的滑块。
这将是一个自定义组件,创建起来是一项中等但有趣的任务。困难的部分是让它在用户看来是可调整的,而不仅仅是显示一个值。在现实生活中,车速表是只读的。
There is not a default way to do this. However if you are creating a custom component, it sounds like you want some sort of dial that could be grabbed and adjusted rather than a slider that does in a circle.
This would be a custom component that would be a medium but fun task to create. The hard part will be making it appear to the user as something that is adjustable rather than just displaying a value. In real life a speedometer is read-only.
巧合的是,我只是需要这个用于我自己的应用程序,我通过了你的问题,这并没有真正帮助我,然后我看到人们使用 Graphics2D。
我确实总是将 Graphics g 视为一个想要谋杀我全家的 100 头怪物,但我决定面对我的恐惧,得到了一个可以制作三角形的代码,并设法用它制作了一个圆形。
这比我想象的要容易得多:
结果:https:// i.sstatic.net/0OiKL.png
(无法添加图片,缺乏声誉:( )
如果您更喜欢 MetalSliderUI 的外观,请使用它而不是 BasicSliderUI。
By coincidence I was just needing this for my own App, I passed through your question which didn't really help me and then I got to the point I saw people use Graphics2D.
I really always look at Graphics g as a 100-headed monster that wants to murder my whole family, but I decided to face my fears, got a code that made a triangle, and managed to make a circle out of it.
It is so much more easier than I ever thought:
Result: https://i.sstatic.net/0OiKL.png
(Can't add images, lack of reputation :( )
If you prefer the look of a MetalSliderUI, use that one instead of the BasicSliderUI.
据我所知,没有内置函数可以执行此操作。但是,您可以使用诸如 此 JKnob 之类的类并自己添加实际的滑动值。 (实际上,它有一个 getValue() 方法,因此只需调用该方法并除以 pi 即可获取 -1.0 到 1.0 之间的值)
There's no built in function to do this, as far as I know. However, you can use a class such as this JKnob and add the actual sliding value yourself. (Actually, it has a getValue() method, so just call that and divide by pi to get a value from -1.0 to 1.0)