Note that there are some explanatory texts on larger screens.

plurals
  1. POFocus Traversal Policy in TitledPane
    text
    copied!<p>On <a href="https://stackoverflow.com/questions/15238928/javafx-change-focus-traversal-policy">JavaFX: How to change the focus traversal policy?</a> Alexander Kirov show how to customize the focus traversal policy for a JavaFX application. It works fine, but not for <code>TitledPane</code>s. If a node in a <code>TitledPane</code> has focus, the setted <code>TraversalEngine</code> is not called.</p> <p>Here is a full example to show this phenomenon:</p> <pre><code>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); } } </code></pre> <p>The root of the scene is a <code>VBox</code> and the custom <code>TraversalEngine</code> is set to it. If the button <code>foo</code> has the focus and I press [Tab] then <code>te.trav</code> is called and the focus is set to <code>bar</code>. That's how I expected. But when <code>bar</code> has the focus, <code>te.trav</code> is not called. <code>bar</code> is a child of the <code>TitledPane</code>. This behaviour is shown in <a href="https://i.stack.imgur.com/kWqGQ.png" rel="nofollow noreferrer">1</a>.</p> <p>Has anyone a solution for this?</p> <p><img src="https://i.stack.imgur.com/kWqGQ.png" alt="Focus Traversal in TitledPane"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload