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

[Mac] Buttons inside a dialog change their hover state on resize

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • jfx11, jfx12, jfx13, 8
    • javafx
    • macOS 10.13
      macOS 10.14

      ADDITIONAL SYSTEM INFORMATION :
      OS: macOS 10.14.4
      JDK: openjdk-12.0.2

      A DESCRIPTION OF THE PROBLEM :
      It is possible to change the hover state of the buttons inside a dialog without placing the mouse over the button but by mere resizing of the dialog.

      I first run into this on openjdk-11.0.1. Could reproduce it on 12.0.2.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Open a dialog and resize its bottom right corner until the rightmost button is located at the very position, where the mouse was pressed to start the resizing.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The button state is not affected by the resizing.
      ACTUAL -
      The button changes its state to hovered when through resizing of the dialog it is positioned such that it contains the point where the last mouse press had happened.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.beans.value.ChangeListener;
      import javafx.scene.Scene;
      import javafx.scene.control.Alert;
      import javafx.scene.control.Button;
      import javafx.scene.control.ChoiceDialog;
      import javafx.scene.layout.AnchorPane;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.Pane;
      import javafx.stage.Stage;
      import org.jetbrains.annotations.NotNull;

      public class Debugging_hover_on_resize extends Application {

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

        @Override
        public void start(final Stage primaryStage) throws Exception {
          final BorderPane root = new BorderPane();

          final Button button = new Button("Click me");
          button.setOnAction(event -> {
      // showAlert(primaryStage);
      // showChoiceDialog(primaryStage);
            showStageBasedCustomDialog(primaryStage);
          });

          root.setCenter(button);

          primaryStage.setScene(new Scene(root, 600, 400));
          primaryStage.show();
        }

        private void showAlert(final Stage owner) {
          final Alert alert = new Alert(Alert.AlertType.INFORMATION);
          alert.initOwner(owner);
          alert.setResizable(true);
          alert.showAndWait();
        }

        private void showChoiceDialog(final Stage owner) {
          final ChoiceDialog<String> choiceDialog = new ChoiceDialog<>("OK", "Cancel");
          choiceDialog.initOwner(owner);
          choiceDialog.setResizable(true);
          choiceDialog.showAndWait();
        }

        // this pseudo-dialog makes the problem most obvious with green buttons on hover
        private void showStageBasedCustomDialog(final Stage owner) {
          final Stage stage = new Stage();
          stage.initOwner(owner);

          final Pane buttonPane = new HBox(12);
          final Button button1 = new Button("OK");
          button1.setOnAction(event -> System.out.println("OK"));
          button1.hoverProperty().addListener(createOnHoverListener(button1));

          final Button button2 = new Button("Cancel");
          button2.setOnAction(event -> System.out.println("Cancel"));
          button2.hoverProperty().addListener(createOnHoverListener(button2));

          buttonPane.getChildren().addAll(button1, button2);

          final AnchorPane root = new AnchorPane();
          root.getChildren().addAll(buttonPane);
          AnchorPane.setBottomAnchor(buttonPane, 12.0);
          AnchorPane.setRightAnchor(buttonPane, 12.0);

          stage.setScene(new Scene(root, 400, 300));
          stage.show();
        }

        @NotNull
        private ChangeListener<Boolean> createOnHoverListener(final Button button) {
          return (observable, wasHovered, isHovered) -> {
            final String style = isHovered ? "-fx-background-color: green;" : "";
            button.setStyle(style);
          };
        }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            arapte Ambarish Rapte
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: