N
N
Neonoviiwolf2016-08-22 18:26:17
Java
Neonoviiwolf, 2016-08-22 18:26:17

How to expand TextField in javaFx, and then Exception falls out?

Good!
I want the TextField, when entering certain (erroneous) values, to correct the result itself. Create a TextField successor class, override the constructor and add an empty setOnAction to it for testing, but the trouble is, when the application starts, I got

Caused by: java.lang.ClassCastException: javafx.scene.control.TextField cannot be cast to mainFx.control.TextFieldControl

TextField I have handles scattered around the scene, you can of course rewrite everything with code, but laziness. Is there a way to get them right? Or am I doing something wrong?
package mainFx.control;

import javafx.scene.control.TextField;

public class TextFieldControl extends TextField {
    public TextFieldControl() {
        super();

        this.setOnAction(event -> {
            System.out.println(1);
        });
    }
}

I want to change to my TextField here
txtName = (TextField) root.lookup("#txtName")

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question