Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8092266

TabPane is given focus when it's content is clicked on

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8u5
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:
    • Environment:

      all

      Description

      I'm not sure about this one so feel free to reject.

      The program below shows a button and a label in a tab. The button has focus on start up. If you click anywhere in the content area apart from on the button, the button loses focus and the tab gains focus.

      If the button has focus and I click on the label for example, I don't think the button should loose focus. I think the focus should stay with the button.

      I still want to be able to click on the tab name and give the tab focus that way, and I still want the shortcut keys to work to switch between tabs.

      I have a workaround at the moment in that I intercept mouse pressed events and just consume them (see commented out code line). The problem with this is I'm not sure it is the correct way to do it and I have to do it for every tab.

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.*;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.layout.FlowPane;
      import javafx.stage.Stage;

      public class FocusTest extends Application {
          @Override
          public void start(Stage stage) throws Exception {
              TabPane tabPane = new TabPane();
              tabPane.setFocusTraversable(false);
              Scene scene = new Scene(tabPane, 500, 500);
              stage.setScene(scene);
              Tab tab = new Tab("Tab 1");
              FlowPane contentPane = new FlowPane();
              /*contentPane.setOnMousePressed(MouseEvent::consume);*/
              tab.setContent(contentPane);
              tabPane.getTabs().addAll(tab, new Tab("Tab 2"));
              Button button = new Button("Button");
              Label label = new Label("Label");
              contentPane.getChildren().addAll(button, label);
              stage.show();
          }

          public static void main(String[] args) {
              Application.launch(args);
          }
      }

      I asked a question about this on stackoverflow but no response (http://stackoverflow.com/questions/24558912/how-do-you-stop-focus-going-to-the-tab-when-clicking-in-the-tabs-content)

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ndarcy Nick D'Arcy
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Imported: