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

Disabled Button retains opacity when enabled

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • tbd
    • jfx11, jfx12, jfx13, 10
    • javafx

      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 it seems to be 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";
      }

            aghaisas Ajit Ghaisas
            jvos Johan Vos
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: