public void initializeTabChangeListener(TabPane tabPane) { ReadOnlyObjectProperty<Tab> itemProperty = tabPane.getSelectionModel().selectedItemProperty(); itemProperty.addListener( (observable, oldValue, selectedTab) -> { if (Objects.isNull(selectedTab)) return; threadService.runActionLater( () -> { EditorPane editorPane = ((MyTab) selectedTab).getEditorPane(); if (Objects.nonNull(editorPane)) { try { editorPane.rerender(); editorPane.focus(); } catch (Exception e) { logger.error("Problem occured after changing tab {}", selectedTab, e); } } }); }); }