如何防止具有选项卡行的 JTabbedPane 在选择时对行重新排序?

发布于 2025-01-05 09:01:56 字数 259 浏览 0 评论 0原文

我有一个带有几行选项卡的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木落 2025-01-12 09:01:56

很抱歉回答我自己的问题,但解决我的问题的简单方法是在我的 MouseAdapter 中第一次单击时捕获选项卡索引,并使用捕获的值(而不是 tabPane.getSelectedIndex() )进行双击工作检测到第二次单击时为当前:

if (evt.getClickCount() == 1 && evt.getComponent() == tabPane) {
    currentTabIndex = tabPane.getSelectedIndex();
}
else if (evt.getClickCount() == 2 && evt.getComponent() == tabPane) {
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                //double-clicked a tab
... {snip}
}

这不会阻止选项卡行四处移动,但会按照用户的预期选择显示第一次单击的选项卡。

此外,为用户提供一个单独的可点击控件来请求选项卡内容的完整显示可能比这种笨拙的双击行为更可取,正如 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:

if (evt.getClickCount() == 1 && evt.getComponent() == tabPane) {
    currentTabIndex = tabPane.getSelectedIndex();
}
else if (evt.getClickCount() == 2 && evt.getComponent() == tabPane) {
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                //double-clicked a tab
... {snip}
}

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!).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文