检测 JSpinner 按钮事件
我需要创建一些 JSpinner 控件,在其中可以检测按钮按下情况,同时使用当前的外观。我发现我可以很容易地做到这一点,如下所示:
class CustomSpinnerUI extends BasicSpinnerUI {
@Override
protected Component createNextButton() {
// Add custom ActionListener.
}
@Override
protected Component createPreviousButton() {
// Add custom ActionListener.
}
}
问题是,通过这样做,我最终会得到一个看起来很恶心的旋转器,它不使用与我的 UI 其余部分相同的外观和感觉。我目前正在使用 Nimbus
,但我需要支持不同的 L&F 配置。
我考虑过设置某种动态代理,但找不到任何合适的 Spinner 接口来帮助我做到这一点。
有人能想办法解决这个问题吗?我想我要么需要在不子类化 BasicSpinnerUI
的情况下访问按钮 ActionListeners
,要么找到一种方法让我的 CustomSpinnerUI
使用正确的 L& F。
编辑:“默认外观和感觉”-> “当前的外观和感觉”。
I need to create some JSpinner controls where I can detect the button presses, whilst using the current look and feel. I have found I can do this easily enough as follows:
class CustomSpinnerUI extends BasicSpinnerUI {
@Override
protected Component createNextButton() {
// Add custom ActionListener.
}
@Override
protected Component createPreviousButton() {
// Add custom ActionListener.
}
}
The problem is that by doing this I end up with a nasty-looking spinner which doesn't use the same look and feel as the rest of my UI. I'm currently using Nimbus
but I need to support different L&F configurations.
I thought about possibly setting up some sort of dynamic proxy, but couldn't find any suitable Spinner
interfaces to enable me to do that.
Can anyone think of a way around the problem? I figure I either need to get at the button ActionListeners
without subclassing BasicSpinnerUI
, or work out a way to have my CustomSpinnerUI
use the correct L&F.
Edit: "default look and feel" -> "current look and feel".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于(公认假设的)问题“如何访问用于挂钩自定义 actionListener 的按钮”的一个肮脏的技术答案是循环遍历微调器的子级并将侦听器添加到按钮,由它们的名称标识:
a dirty technical answer to (concededly assumed) problem "how to access the buttons for hooking-in a custom actionListener" is to loop through the spinner's children and add the listeners to the buttons, identified by their name: