4

I need to be able to click into focus on a Pane. For most other nodes, this works by default -- for some reason this isn't working for a Pane.

My scene:

Border Pane > Scroll Pane > Anchor Pane > Pane

I have tried calling pane.setFocusTraversable(), however then I can only tab into the plane. I need to be able to click into it.

Any ideas? Thanks in advance.

haz
  • 2,034
  • 4
  • 28
  • 52
  • 1
    Try adding an on click event that calls requestFocus()? Im not 100% if thatll work because the currently focused pane may consume that event. Worth a try though. Edit. I found this by a short google. It may solve your problem. http://stackoverflow.com/questions/21798183/focus-listener-for-javafx-nodes – Hypnic Jerk Sep 18 '16 at 05:40

1 Answers1

0
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Focus extends Application {

    @Override
    public void start(Stage primaryStage) {
        TextField t1 = new TextField();
        tf1.setPromptText("Enter Text");
        TextField t2 = new TextField();
        tf2.setPromptText("Enter Text");
        VBox root = new VBox(5, t1, t2);
        primaryStage.setScene(new Scene(root, 250, 150));
        primaryStage.show();
        root.requestFocus();
    }
}