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

JavaFX does not repaint when removing an object drawn on top of another object

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u25
    • javafx
    • None
    • Windows 7 / Java 1.8.0 64-Bit Server VM build 25.0-b70

      In the code below, the green rectangle is not removed on mouse click. However, if you resize the stage after the mouse click, the scene is repainted and the green rect vanishes.

      If you set the green rectangle's size to 150/150, then some of it is immediately on top of the pane, and it vanishes immediately on mouse click.

      {code}
      package demo;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.layout.Pane;
      import javafx.scene.paint.Color;
      import javafx.scene.shape.Rectangle;
      import javafx.stage.Stage;

      public class Main3 extends Application {
          public static void main(String[] args) {
              Application.launch(Main3.class.getName());
          }

          public Main3() {}

          @Override
          public void start(Stage stage) throws Exception {
              Pane pane = new Pane();
              Rectangle rect = new Rectangle(10, 10, 200, 200);
              pane.getChildren().add(rect);
              stage.setScene(new Scene(pane, 300, 300));
              stage.show();

              Rectangle rect2 = new Rectangle(100, 100, 50, 50);
              rect2.setFill(Color.GREEN);
              pane.getChildren().add(rect2);

              pane.setOnMouseClicked(event -> pane.getChildren().remove(rect2));
          }
      }
      {code}

            Unassigned Unassigned
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Imported: