CSS style class rendering bug

David Grieve david.grieve at oracle.com
Tue Aug 1 15:02:30 UTC 2017


Smells like a bug to me.


On 8/1/17 10:08 AM, adam at adamish.com wrote:
> (https://stackoverflow.com/questions/45440102/javafx-css-class-not-removed-when-node-disconnected)
>
> I appeared to have discovered a case in JavaFX (8u144, running on
> Windows 7) where a TextField is rendered using the wrong style class.
>
> This only appears to happen in the following situation
>
>   * style class removed whilst Node not attached to Scene AND
>   * parent `GridPane` has a style-class assigned, even if that class
> doesn't have content.
>
> I've separated the issue from a larger application into the following
> contrived example:
>
>      public class RenderBug extends Application {
>      
>          private static final String ERROR = "error";
>      
>          public static void main(String[] args) {
>              launch(args);
>          }
>      
>          @Override
>          public void start(Stage primaryStage) throws Exception
> {
>              TextField field = new TextField();
>              GridPane grid = new GridPane();
>              grid.getStyleClass().add("some-random-class");
>              grid.add(field, 0, 0);
>      
>              StackPane stack = new StackPane(grid);
>      
>              Scene scene = new Scene(stack);
>              scene.getStylesheets().add("/foo.css");
>              primaryStage.setWidth(300);
>              primaryStage.setHeight(300);
>              primaryStage.setScene(scene);
>              primaryStage.show();
>      
>              Timeline line = new Timeline();
>      
>              line.getKeyFrames().add(new
> KeyFrame(Duration.seconds(4), event -> {
>                  field.getStyleClass().add(ERROR);
>              }));
>              line.getKeyFrames().add(new
> KeyFrame(Duration.seconds(5), event -> {
>                  stack.getChildren().remove(grid);
>              }));
>              line.getKeyFrames().add(new
> KeyFrame(Duration.seconds(6), event -> {
>                  field.getStyleClass().remove(ERROR);
>              }));
>              line.getKeyFrames().add(new
> KeyFrame(Duration.seconds(7), event -> {
>                  stack.getChildren().add(grid);
>                 
> System.out.println(field.getStyleClass());
>              }));
>      
>              line.play();
>          }
>      
>      }
>
> foo.css
>
>      .text-field.error {
>          -fx-background-color: red;
>      }
>      
>      .some-random-class {
>          /** no content required */
>      }
>
> Screenshot. At this point TextField is red, even though the class
> "error" has been removed. Even interacting with the field, resizing
> window etc. does not fix the issue.
>
> [![TextField shown with red][1]][1]
>
> Is this a genuine bug? or am I doing something wrong? I can't find any
> documentation to hint that style-classes cannot or shouldn't be
> updated "offline"
>
>    [1]: https://i.stack.imgur.com/ZPEYi.png
>
>



More information about the openjfx-dev mailing list