3

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.

oldingn
  • 86
  • 4
  • 2
    I don't see this behavour when using the Metal LAF. There is no reordering of the tab. Post your SSCCE that demonstrates the problem. However, I don't think this should be functionality for a tab. If you want to have a detail view, the add a "Details" button to the panel added to the tab. – camickr Feb 15 '12 at 01:13
  • I may not have been clear: If I click on a tab in the third row, that row is moved to become the first row, resulting in the cursor now being positioned above a different tab in what was the first row that has now become the third row. – oldingn Feb 15 '12 at 17:22

1 Answers1

0

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

oldingn
  • 86
  • 4