If a TextField's "disable" property is set to true while it still has focus then when it is re-enabled its disabled appearance remains even though it is actually re-enabled.
Run the provided test case below and click on the Enable/Disable button. When you click it the first time the field properly disables. Click on it again and the field still looks disabled but if you then try to use the it you will see that it is actually enabled but still has its disabled overlay.
If you comment out the line button.setFocusTraversable(false); then the issue goes away.
********************* Test Case ****************************
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class FieldTest extends Application {
@Override
public void start(final Stage primaryStage) throws Exception {
primaryStage.setWidth(600);
primaryStage.setHeight(400);
primaryStage.centerOnScreen();
final TextField field = new TextField("Hey...");
final Button button = new Button("Disable/Enable");
button.setFocusTraversable(false);
button.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent arg0) {
field.setDisable(!field.isDisabled());
}
});
HBox box = new HBox( 10, field, button );
box.setAlignment(Pos.CENTER);
primaryStage.setScene( new Scene(new StackPane(box)) );
primaryStage.show();
}
public static void main(String[] args) throws Exception{
launch(args);
}
}
Run the provided test case below and click on the Enable/Disable button. When you click it the first time the field properly disables. Click on it again and the field still looks disabled but if you then try to use the it you will see that it is actually enabled but still has its disabled overlay.
If you comment out the line button.setFocusTraversable(false); then the issue goes away.
********************* Test Case ****************************
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class FieldTest extends Application {
@Override
public void start(final Stage primaryStage) throws Exception {
primaryStage.setWidth(600);
primaryStage.setHeight(400);
primaryStage.centerOnScreen();
final TextField field = new TextField("Hey...");
final Button button = new Button("Disable/Enable");
button.setFocusTraversable(false);
button.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent arg0) {
field.setDisable(!field.isDisabled());
}
});
HBox box = new HBox( 10, field, button );
box.setAlignment(Pos.CENTER);
primaryStage.setScene( new Scene(new StackPane(box)) );
primaryStage.show();
}
public static void main(String[] args) throws Exception{
launch(args);
}
}