Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8145883

setStyle(null) on TextField with custom skin not working correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u66
    • javafx
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_66"
      Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
      Java HotSpot(TM) Client VM (build 25.66-b18, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      I have a scene with a text field that has a custom skin which derives from com.sun.javafx.scene.control.skin.TextFieldSkin. The -fx-skin ist set in the css.

      Right before primaryStage.show() is called, the setStyle for the text field ist called in a Platform.runLater block setting the -fx-text-fill property.

      when the stage is displayed and i call setStyle(null) for the text field, the text fill will be the property default, not the css default.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a new JavaFx application.

      Create a class that derives from com.sun.javafx.scene.control.skin.TextFieldSkin without any modifications.

      In the style sheet for the application set the -fx-skin property for the .text-field class to the derived skin created before.

      Add a TextField to the scene.
      Load the style sheet to the scene.

      In a Platform.runLater block call setStyle("-fx-text-fill: ... at the text field.

      call primaryStage.show().

      call setStyle(null) at the text field.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      After setStyle(null), the text fill of the fext field shoud be the value specified in css.
      ACTUAL -
      After setStyle(null), the text fill of the fext field is the default value of the textFill property of the TextInputControlSkin.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class StyleTest extends Application {

        private HBox root = new HBox(15);

        private TextField textField = new TextField("some text");
        private Button button = new Button("#");

        private EventHandler<ActionEvent> buttonHandler = new EventHandler<ActionEvent>() {
          private boolean doStyle = true;

          @Override
          public void handle(ActionEvent event) {
            String styleString = doStyle ? "-fx-text-fill: green;" : null;
            textField.setStyle(styleString);
            doStyle = !doStyle;
          }
        };


        @Override
        public void start(Stage primaryStage) throws Exception {
          button.setOnAction(buttonHandler);

          root.getChildren().setAll(textField, button);

          primaryStage.setScene(new Scene(root));
          primaryStage.getScene().getStylesheets()
              .add(getClass().getResource("styleTest.css").toExternalForm());


          Platform.runLater(() -> {
            buttonHandler.handle(null);
          });

          
          primaryStage.show();
          button.requestFocus();
        }
        
        public static class CustomTextFieldSkin extends TextFieldSkin {

          public CustomTextFieldSkin(TextField textField) {
            super(textField);
          }
          
        }
      }


      ///////////////////////////////////////////////////////////////////////////////////////////////
      //content of the css style sheet "styleText.css":
      .text-field {
      -fx-text-fill: red;
      -fx-skin: "test.StyleTest$CustomTextFieldSkin";
      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: