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

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



    • Enhancement
    • Status: Open
    • P4
    • Resolution: Unresolved
    • 8u5
    • tbd
    • javafx
    • all


      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 {
          public void start(Stage stage) throws Exception {
              TabPane tabPane = new TabPane();
              Scene scene = new Scene(tabPane, 500, 500);
              Tab tab = new Tab("Tab 1");
              FlowPane contentPane = new FlowPane();
              tabPane.getTabs().addAll(tab, new Tab("Tab 2"));
              Button button = new Button("Button");
              Label label = new Label("Label");
              contentPane.getChildren().addAll(button, label);

          public static void main(String[] 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)




            Unassigned Unassigned
            ndarcy Nick D'Arcy
            0 Vote for this issue
            1 Start watching this issue