获取JTable焦点时出现问题?
这是场景: 我有一个 nxn 的 JTable。在每个单元格的 Col(0) 中,有一个滑块,其中两个拇指分别代表最小值和最大值,两个 JTextField 代表最小值和最大值。
每当我第一次单击单元格时,滑块不会响应,但第二次单击时滑块会响应。
我的猜测是,第一次单击时 JTable 获得焦点,第二次单击单元格时。
希望单元格在第一次单击时做出响应。
提前谢谢您...
This is the scenario:
I have a JTable of nxn. In the Col(0) of each cell, have a slider with two thumbs each for min and max,two JTextField to represent min and max.
Whenever i click for first time on the cell, slider doesn't responds but on the second click the slider responds.
My guess is that on the first click the JTable gets the focus and on the second click the cell.
would like the cell to respond on the first click.
Thank you on advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置
setClickCountToStart(1)
,更多说明此处set
setClickCountToStart(1)
, more descriptions here由于我没有看到您的代码,我猜想是 FocusTraTraversalPolicy 导致了您的问题。
在 Swing 的每个容器中,组件都有一个预定义的获取焦点的顺序。当您按下键盘上的 Tab 按钮时,它们会按顺序获得焦点。所以当你第一次点击一个容器时,有一个默认的组件获得焦点,如果你对它不满意,你可以使用 FocusTraversalPolicy 来修改它。
查看此lnk,它可能会对您有所帮助。
As I didn't see your code, I guess it's the FocusTraTraversalPolicy that is causing your problem.
In each container of Swing, the components have a predefined order of getting focus. They get the focus in order when you press the Tab button on the keyboard. So when you first click a container, there's a default component that gets the focus, if you're not satisfied with it, you can use the FocusTraversalPolicy to modify it.
Check this lnk out, it may help you.