如何从拇指上取消 JSlider 进度指示器的链接?
我使用 JSlider 来显示应用程序的进度,以便它随着特定进程的计算而更新。
我希望用户能够将拇指向后拖动到过去的刻度线,但是当发生这种情况时,我希望进度指示器保持在当前位置。
// A dismal attempt at drawing the situation
Progress: ---------
Thumb: |
// User drags backwards. What I have:
Progress: ---
Thumb: |
// What I want instead:
Progress: ---------
Thumb: |
任何人都可以提供有关如何最好地实现这一目标的任何指导吗? 预先感谢所有帮助!
I'm using a JSlider to show progress in my application, so that it updates as a certain process computes.
I want a user to be able to drag the thumb backwards to a tick mark in the past, but when this happens, I want the progress indicator to remain at its current position.
// A dismal attempt at drawing the situation
Progress: ---------
Thumb: |
// User drags backwards. What I have:
Progress: ---
Thumb: |
// What I want instead:
Progress: ---------
Thumb: |
Can anyone offer any guidance for how to best accomplish this?
Thanks in advance for all help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
啊,我明白你的意思了。不幸的是,没有办法做到这一点。
“蓝色条”实际上并不是 JSlider 的一部分,它是 Metal LAF 的一部分。这只是 Metal LAF 选择绘制组件的方式。如果您尝试使用另一个 LAF,则根本看不到该条。
您需要将 JProgressBar 和 JSlider 结合起来才能获得您想要的效果,
您需要对其进行调整以使其看起来正确。
Ah, I see what you mean. Unfortunately, there's no way to do that.
The 'blue bar" is not really part of JSlider, it's part of the Metal LAF. It's just the way the Metal LAF chose to paint the component. If you try it with another LAF you don't get the bar at all.
You'll need to couple a JProgressBar and a JSlider to get what you want.
Here's a starting point. You'll need to tweak it to get it to look right
我想通了。我扩展了 JSlider 以单独跟踪当前拇指位置的进度,然后重写 MetalSliderUI 的 PaintTrack 方法以将轨道绘制到我想要的位置。
这是解决方案,去掉了重要部分。
新的进度条:
新的用户界面:
请注意,仅在 UI 类中的 PaintTrack() 方法中添加了 2 行,紧跟在注释后面。
并让驱动程序对其进行测试:
I figured it out. I extended JSlider to keep track of the progress separately from the current thumb position, and then overrode the MetalSliderUI's paintTrack method to draw fill the track to the position I want.
Here's the solution, stripped down the important parts.
The new progress bar:
The new UI:
Note, there were only 2 lines added to the paintTrack() method in the UI class, immediately following the comment saying such.
And for the driver to test it:
好吧,我不明白这怎么可能。您将需要自定义滑块 UI 并更改模型,因为您不需要存储两条模型信息:“跟踪值”和“拇指值”。
如果你想要一个大技巧,那么你可以在另一个之上绘制两个滑块。底部滑块用于轨道值,顶部滑块用于拇指值。
您还需要重叠布局。如何使它们保持同步取决于您。该解决方案有很多缺陷,但它可能会给您一些想法。
Well I don't see how this is possible. You will need to customize the slider UI and change the model because no you need to store two pieces of model information, the "track value" and the "thumb value".
If you want a big hack, then you paint two sliders on top of one another. The bottom slider would be for the track value and the top would be for the thumb value.
You will also need the Overlap Layout. How you keep them in sync would be up to you. The solution has many flaws, but it may give you some ideas.