java - Focus Traversal Policy in TitledPane -


on javafx: how change focus traversal policy? alexander kirov show how customize focus traversal policy javafx application. works fine, not titledpanes. if node in titledpane has focus, setted traversalengine not called.

here full example show phenomenon:

package org.example;  import com.sun.javafx.scene.traversal.direction; import com.sun.javafx.scene.traversal.traversalengine;  import javafx.application.application; import javafx.scene.node; import javafx.scene.scene; import javafx.scene.control.button; import javafx.scene.control.titledpane; import javafx.scene.layout.pane; import javafx.scene.layout.vbox; import javafx.stage.stage;  public class focustest extends application {     @override     public void start(stage primarystage) throws exception {         // create ui         final vbox root = new vbox();         final button foo = new button("foo");         foo.setid("foo");         root.getchildren().add(foo);         final button bar = new button("bar");         bar.setid("bar");         final pane content = new pane();         content.getchildren().add(bar);         final titledpane tp = new titledpane("tp", content);         root.getchildren().add(tp);          // set traversalengine         final traversalengine te = new traversalengine(root, false) {             @override             public void trav(node owner, direction direction) {                 system.out.printf("trav owner: %s, direction: %s%n",                         owner.getid(), direction);                 switch (direction) {                 case down:                 case right:                 case next:                     if (owner == foo) {                         bar.requestfocus();                     } else if (owner == bar) {                         foo.requestfocus();                     }                     break;                 case left:                 case previous:                 case up:                     if (owner == foo) {                         bar.requestfocus();                     } else if (owner == bar) {                         foo.requestfocus();                     }                     break;                 }             }         };         root.setimpl_traversalengine(te);          // show scene         final scene scene = new scene(root);         primarystage.setheight(200);         primarystage.setscene(scene);         primarystage.show();     }      public static void main(string[] args) {         launch(args);     } } 

the root of scene vbox , custom traversalengine set it. if button foo has focus , press [tab] te.trav called , focus set bar. that's how expected. when bar has focus, te.trav not called. bar child of titledpane. behaviour shown in 1.

has solution this?

focus traversal in titledpane

this tricky solution deals titledpanes:

@suppresswarnings("deprecation") private static void registertraversalengine(final parent parent,         final traversalengine te) {     parent.setimpl_traversalengine(te);     (node child : parent.getchildrenunmodifiable()) {         if (child instanceof parent) {             registertraversalengine((parent) child, te);         }     }     if (parent instanceof titledpane) {         final titledpane tp = (titledpane) parent;         if (tp.getcontent() instanceof parent) {             registertraversalengine((parent) tp.getcontent(), te);         }     } } 

i think problem titltedpanes is, content not in children set:

titledpane.getchildrenunmodifiable().contains(titledpane.getcontent()) false 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -