title: remove focus from TextField JavaFX
body: <p>I can not remove focus from the <code>TextField</code>. On my view I only have one editable content: Text in a <code>TextField</code>. The problem is that as a user one never gets rid of the focus (because there is nothing else to focus on), once the <code>TextField</code> is focused. I want to remove the focus from the <code>TextField</code>. </p>
  
  <p><a href="https://i.stack.imgur.com/k0THg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k0THg.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/T726m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T726m.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/Yb62p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yb62p.png" alt="enter image description here"></a></p>
  
  <pre><code>public class ControllerMain implements Initializable {
      private MainApp app;
      private ObservableList&lt;UserData&gt; data = FXCollections.observableArrayList();
      @FXML
      private Button btnAdd;
      @FXML
      public TableView&lt;UserData&gt; table = new TableView&lt;&gt;();
      @FXML
      private TableColumn&lt;UserData, String&gt; column1;
      @FXML
      private TableColumn&lt;UserData, Integer&gt; column2;
      @FXML
      private TableColumn&lt;UserData, String&gt; column3;
      @FXML
      private TableColumn&lt;UserData, String&gt; column4;
      @FXML
      private TableColumn&lt;UserData, Integer&gt; column5;
      @FXML
      private TextField txtSearch;
  
      public ControllerMain() {
      }
  
      public void setApp(MainApp instance) {
          this.app = instance;
      }
  
  
      @Override
      public void initialize(URL location, ResourceBundle resources) {
          String companyName = "companyName";
          column1.setCellValueFactory(new PropertyValueFactory&lt;&gt;(companyName));
          String phone = "phone";
          column2.setCellValueFactory(new PropertyValueFactory&lt;&gt;(phone));
          String address = "address";
          column3.setCellValueFactory(new PropertyValueFactory&lt;&gt;(address));
          String other = "other";
          column4.setCellValueFactory(new PropertyValueFactory&lt;&gt;(other));
          String id = "id";
          column5.setCellValueFactory(new PropertyValueFactory&lt;&gt;(id));
          column5.setVisible(false);
          initSearchFilter();
      }
  
      private void initSearchFilter() {
          txtSearch.textProperty().addListener(o -&gt; {
              if (txtSearch.textProperty().get().isEmpty()) {
                  table.setItems(data);
                  return;
              }
              ObservableList&lt;UserData&gt; tableItems = FXCollections.observableArrayList();
              ObservableList&lt;TableColumn&lt;UserData, ?&gt;&gt; cols = table.getColumns();
              for (UserData aData : data) {
                  for (TableColumn&lt;UserData, ?&gt; col1 : cols) {
                      String cellValue = col1.getCellData(aData).toString();
                      cellValue = cellValue.toLowerCase();
                      if (cellValue.contains(txtSearch.textProperty().get().toLowerCase())) {
                          tableItems.add(aData);
                          break;
                      }
                  }
              }
              table.setItems(tableItems);
          });
      }
  
      @FXML
      private void handleOpenAddForm() throws IOException {
          UserData userData = new UserData();
          app.initAddForm();
          getData().add(userData);
          loadDatabaseData();
      }
  
      @FXML
      private void deleteHandle() {
          try (Connection con = new DBConnect().getConnected();
               PreparedStatement prep = con.prepareStatement("DELETE FROM job.job WHERE job.id = ?")) {
              UserData selectedItem = table.getSelectionModel().getSelectedItem();
              prep.setInt(1, selectedItem.getId());
              prep.execute();
              getData().remove(selectedItem);
              loadDatabaseData();
          } catch (Exception e) {
              System.err.println("Ошибка удаления: " + e.getMessage());
          }
      }
  
      @FXML
      private void handleOpenUpdateForm() throws IOException {
          UserData userData = table.getSelectionModel().getSelectedItem();
          app.initUpdateForm(userData);
          userData.setId(userData.idProperty().getValue());
          userData.setCompanyName(userData.companyNameProperty().getValue());
          userData.setPhone(userData.phoneProperty().getValue());
          userData.setAddress(userData.addressProperty().getValue());
          userData.setOther(userData.otherProperty().getValue());
          loadDatabaseData();
      }
  
      public void loadDatabaseData() {
          try (Connection con = new DBConnect().getConnected();
               PreparedStatement preparedStatement = con.prepareStatement("SELECT  * FROM job.job");
               ResultSet resultSet = preparedStatement.executeQuery()) {
              getData().clear();
              while (resultSet.next()) {
                  getData().add(new UserData(
                          resultSet.getInt("id"),
                          resultSet.getString("company_name"),
                          resultSet.getInt("phone"),
                          resultSet.getString("address"),
                          resultSet.getString("other")
                  ));
                  table.setItems(getData());
              }
  
              txtSearch.setFocusTraversable(false);
          } catch (Exception e) {
              e.printStackTrace();
              System.out.println("Error on Building Data");
          }
      }
  
      private ObservableList&lt;UserData&gt; getData() {
          return data;
      }
  
  
  }
  </code></pre>
  
  <p>FXML</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
          prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
          fx:controller="com.mysoft.controller.ControllerMain"&gt;
   &lt;center&gt;
          &lt;TableView fx:id="table" prefHeight="370.0" prefWidth="613.0" BorderPane.alignment="CENTER"
                     focusTraversable="false"&gt;
              &lt;columns&gt;
                  &lt;TableColumn fx:id="column1" prefWidth="139.0" text="Название компании"/&gt;
                  &lt;TableColumn fx:id="column2" minWidth="0.0" prefWidth="85.0" text="Телефон"/&gt;
                  &lt;TableColumn fx:id="column3" minWidth="0.0" prefWidth="217.0" text="Адрес"/&gt;
                  &lt;TableColumn fx:id="column4" minWidth="0.0" prefWidth="156.0" text="Другое"/&gt;
                  &lt;TableColumn fx:id="column5" minWidth="0.0" prefWidth="156.0" text="ID"/&gt;
              &lt;/columns&gt;
          &lt;/TableView&gt;
      &lt;/center&gt;
      &lt;bottom&gt;
          &lt;GridPane BorderPane.alignment="CENTER"&gt;
              &lt;columnConstraints&gt;
                  &lt;ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/&gt;
                  &lt;ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/&gt;
                  &lt;ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/&gt;
              &lt;/columnConstraints&gt;
              &lt;rowConstraints&gt;
                  &lt;RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/&gt;
              &lt;/rowConstraints&gt;
              &lt;BorderPane.margin&gt;
                  &lt;Insets left="30.0" right="20.0"/&gt;
              &lt;/BorderPane.margin&gt;
              &lt;Button mnemonicParsing="false" prefHeight="25.0" prefWidth="170.0" text="Добавить"
                      focusTraversable="false" onAction="#handleOpenAddForm"/&gt;
              &lt;Button mnemonicParsing="false" prefHeight="25.0" prefWidth="170.0" text="Редактировать"
                      GridPane.columnIndex="1" focusTraversable="false" onAction="#handleOpenUpdateForm"/&gt;
              &lt;Button mnemonicParsing="false" prefHeight="25.0" prefWidth="170.0" text="Удалить"
                      GridPane.columnIndex="2" focusTraversable="false" onAction="#deleteHandle"/&gt;
          &lt;/GridPane&gt;
      &lt;/bottom&gt;
      &lt;top&gt;
          &lt;GridPane BorderPane.alignment="CENTER"&gt;
              &lt;columnConstraints&gt;
                  &lt;ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" maxWidth="268.0" minWidth="10.0"
                                     prefWidth="259.0"/&gt;
                  &lt;ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" maxWidth="357.0" minWidth="10.0"
                                     prefWidth="321.0"/&gt;
              &lt;/columnConstraints&gt;
              &lt;rowConstraints&gt;
                  &lt;RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/&gt;
              &lt;/rowConstraints&gt;
              &lt;padding&gt;
                  &lt;Insets left="20.0"/&gt;
              &lt;/padding&gt;
              &lt;TextField prefHeight="25.0" prefWidth="206.0" promptText="Введите данные для поиска . . ."
                          fx:id="txtSearch" focusTraversable="false"&gt;
                  &lt;font&gt;
                      &lt;Font name="Arial Italic" size="12.0"/&gt;
                  &lt;/font&gt;
              &lt;/TextField&gt;
          &lt;/GridPane&gt;
      &lt;/top&gt;
  &lt;/BorderPane&gt;
  </code></pre>