openjdk-jfx icon indicating copy to clipboard operation
openjdk-jfx copied to clipboard

[Regression] Disabled Button retains opacity when enabled

Open abhinayagarwal opened this issue 5 years ago • 0 comments

The opacity property of a custom button, that is initially disabled, is not updated once it has been enabled. The following conditions needs to be met to reproduce the issue:

  • The custom skin on the button is set using -fx-skin via css stylesheet
  • The custom button is a part of a layout which has replaced the original root of the Scene

The bug is reproducible with JavaFX 10, 11, 12 but is not reproducible on JDK 9, which is why I think its a regression.

It seems to be related to https://bugs.openjdk.java.net/browse/JDK-8201285 and to the issues marked as duplicates / related in the said issue.

REPRODUCIBILITY: This bug can be reproduced always.

SCSS

CustomButtonSkin.java

import javafx.scene.control.Button;
import javafx.scene.control.skin.ButtonSkin;

public class CustomButtonSkin extends ButtonSkin {

    public CustomButtonSkin(Button button) {
        super(button);
    }
}

Main.java

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) {
        BorderPane borderPane = new BorderPane();

        Button button = new Button("Click me!");
        button.setOnAction(e -> {
            Button disabled = new Button("Disabled");
            disabled.setDisable(true);
            Button enable = new Button("Enable");
            enable.setOnAction(ev -> disabled.setDisable(! disabled.isDisable()));
            final HBox root = new HBox(5, enable, disabled);
            root.setAlignment(Pos.CENTER);
            root.getStyleClass().setAll("view");
            borderPane.setCenter(root);
        });

        VBox root = new VBox(20, button);
        root.setAlignment(Pos.CENTER);

        borderPane.setCenter(root);

        final Scene scene = new Scene(borderPane, 300, 275);
        scene.getStylesheets().add(getClass().getResource("custom.css").toExternalForm());
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

custom.css

.view {
}

.button {
    -fx-skin: "sample.CustomButtonSkin";
}

abhinayagarwal avatar Aug 23 '19 11:08 abhinayagarwal