I need to switch tabs on Ctrl-Tab and Ctrl-Shift-Tab. But it works only when TabPane is in focus. I have Tabs with setContent(textArea). When textArea is in focus, and I press Ctrl-Tab, focus goes somewhere in menu:
TextArea@3f40a15a[styleClass=text-input text-area]
TextArea@7b7c82a4[styleClass=text-input text-area]
TabPane[id=null, styleClass=tab-pane]
TextArea[id=null, styleClass=text-input text-area]
MenuButtonSkinBase$MenuLabeledImpl[id=null, styleClass=label]
TextArea[id=null, styleClass=text-input text-area]
MenuButtonSkinBase$MenuLabeledImpl[id=null, styleClass=label]
TextArea[id=null, styleClass=text-input text-area]
TabPane[id=null, styleClass=tab-pane]
TextArea[id=null, styleClass=text-input text-area]
MenuButtonSkinBase$MenuLabeledImpl[id=null, styleClass=label]
TextArea[id=null, styleClass=text-input text-area]
I track focus changes like this:
scene.focusOwnerProperty().addListener(new ChangeListener<Node>() {
@Override
public void changed(ObservableValue<? extends Node> ov, Node t, Node t1) {
System.out.println(t1);
}
});
I have setFocusTraversable to false almost on every component(including menu, toolbar, textArea and panes)
I created Tabs and used setContent(textArea).
Also I want to requestFocus on textArea every time user open/close tab and switch between tabs(using mouse and keyboard hotkeys).
tabPane.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
Platform.runLater(new Runnable() {
@Override
public void run() {
if (tabPane.getTabs().size() > 0) {
FileTab tab = (FileTab)tabPane.getTabs().get(tabPane.getSelectionModel().getSelectedIndex());
tab.getTextArea().requestFocus();
}
}
});
}
});
This does not work. I tried tab.getContent().requestFocus() - doesn't work too.
About changing tabs when TabPane child is in focus: It seems like TabPane gets KeyEvent, but because it's not in focus(textArea in focus), it just skips this event. Maybe I could duplicate default functionality by firing KeyEvent at TabPane or maybe even re implement it on my own. Or maybe I could call nextTab/previousTab default actions from this listener:
tabPane.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler() {
@Override
public void handle(KeyEvent t) {
if (t.getCode().equals(KeyCode.TAB) && t.isControlDown()) {
//Event.fireEvent(tabPane, event); //I'm not sure how to do it like this
//Maybe it's better to just call default actions on TabPane.
t.consume();
}
}
});
http://s23.postimg.org/poeujzwbf/screenshot_185.png
But I still don't know how to set focus on TextArea after tab switch. Maybe I should try to call Platform.runLater() after some delay?