1 Reply Latest reply on Dec 13, 2012 6:54 PM by jsmith

    Strange problem with Canvas


      I have a Canvas, where I draw semi-transparent shapes.

      If I add another control (Button) to the scene, the canvas behaves very strangely. It seems to repaint itself everytime I trigger some action, which causes the shapes to get more intensive (and no longer transparent).

      Here's a sample:

      Trigger the problem by hovering and unhovering the button. Or by switching the window's focus by using ALT+TAB several times and see, how the transparent light red rectangle becomes a solid red.

      Where's the problem?
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.canvas.Canvas;
      import javafx.scene.canvas.GraphicsContext;
      import javafx.scene.control.Button;
      import javafx.scene.layout.StackPane;
      import javafx.scene.layout.VBox;
      import javafx.scene.paint.Color;
      import javafx.stage.Stage;
      public class TestApp3 extends Application {
          public static void main(String[] args) {
          public void start(final Stage stage) throws Exception {
              VBox root = new VBox();
              Canvas canvas = new Canvas();
              GraphicsContext graphicsContext = canvas.getGraphicsContext2D();
              graphicsContext.setFill(Color.rgb(255, 0, 0, 0.1));
              graphicsContext.fillRect(0, 0, 300, 300);
              root.getChildren().add(new Button());
              Scene scene = new Scene(root);
      Edited by: csh on 13.12.2012 05:37
        • 1. Re: Strange problem with Canvas
          How bizarre.

          I get the same behaviour you describe.

          I tried your test in jdk7u6 (JavaFX 2.2.3) and jdk8b67, Win7, Radeon HD graphics.

          If the vbox spacing is set to 20, then the button doesn't overlap the canvas and when you mouseover the canvas it is fine.
          I don't really know why it overlaps the canvas when the spacing is 0 either . . .

          Anyway, file a bug . . .