I got a ScrollPane containing custom nodes.
Current default behavior:
Shift + β , β , β , β moves focus
β , β , β , β scrolls the view
I want everything to be the other way around. How can I do this or where to start?
[EDIT] Well, thereβs another fragile approach.
Instead of messing around with events, you can collect KeyBinding s.
scrollPane.skinProperty().addListener(new ChangeListener<Skin<?>>() { @Override public void changed(ObservableValue<? extends Skin<?>> observable, Skin<?> oldValue, Skin<?> newValue) { ScrollPaneSkin scrollPaneSkin = (ScrollPaneSkin) scrollPane.getSkin(); ScrollPaneBehavior scrollPaneBehavior = scrollPaneSkin.getBehavior(); try { Field keyBindingsField = BehaviorBase.class.getDeclaredField("keyBindings"); keyBindingsField.setAccessible(true); List<KeyBinding> keyBindings = (List<KeyBinding>) keyBindingsField.get(scrollPaneBehavior); List<KeyBinding> newKeyBindings = new ArrayList<>(); for (KeyBinding keyBinding : keyBindings) { KeyCode code = keyBinding.getCode(); newKeyBindings.add(code == KeyCode.LEFT || code == KeyCode.RIGHT || code == KeyCode.UP || code == KeyCode.DOWN ? keyBinding.shift() : keyBinding); } keyBindingsField.set(scrollPaneBehavior, newKeyBindings); } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { LOGGER.warn("private api changed.", e); } } });
I think this could be a cleaner way if KeyBindings were more non-statistical, modifiable, and public.
source share