如何防止具有选项卡行的 JTabbedPane 在选择时对行重新排序?
我有一个带有几行选项卡的 Swing JTabbedPane,它们显示应用程序各个部分的摘要信息。 我想让用户双击任何选项卡以在窗口中显示完整内容,但是当在除第一行之外的任何选项卡上检测到第一次单击时,选项卡行都会移动。第二次单击被检测为双击,但现在光标下方有一个不同的选项卡(由于原始选项卡行被移动到前面),并且显示错误的窗口。
如何防止选项卡行重新排序,或者如何才能轻松地允许用户在单击任何给定选项卡时查看关联数据?
编辑:尝试澄清:行的移动,而不是行内选项卡的移动。
I have a Swing JTabbedPane with several rows of tabs, which show summary information from various parts of my application.
I'd like to let the user double-click on any tab to display the full contents in a window, but the tab rows are moved around when the first click is detected on a tab in anything but the first row. The second click is detected as a double-click, but now a different tab is under the cursor (due to the original tab row being moved to the front), and the wrong window is displayed.
How can I prevent the tab rows from reordering, or, how else can I easily allow the user to view associated data when clicking on any given tab?
Edit: attempt to clarify: the movement of rows, rather than the movement of tabs within rows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很抱歉回答我自己的问题,但解决我的问题的简单方法是在我的 MouseAdapter 中第一次单击时捕获选项卡索引,并使用捕获的值(而不是 tabPane.getSelectedIndex() )进行双击工作检测到第二次单击时为当前:
这不会阻止选项卡行四处移动,但会按照用户的预期选择显示第一次单击的选项卡。
此外,为用户提供一个单独的可点击控件来请求选项卡内容的完整显示可能比这种笨拙的双击行为更可取,正如 camickr 所建议的那样(谢谢!)。
Apologies for answering my own question, but the simple work-around for my problem is to capture the tab index on the first click in my MouseAdapter, and do double-click work using the captured value, rather than the tabPane.getSelectedIndex() that is current when the second click is detected:
This does not prevent the tab rows being moved around, but the first-clicked tab is selected for display, as expected by the user.
Also, having a separate clickable control for the user to request the full display of a tab's contents is probably preferable to this clumsy double-clicking behaviour, as camickr suggested (thanks!).