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

Instantiating javafx.scene.control overlays Scene fill

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • jfx14
    • javafx
    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      First hit this problem on Windows 10 with Oracle SE 8. Tried it on Windows 10 with OpenJDK 8 - same. Tried on OpenJDK/OpenJFX13 on Linus - same. AS per reporting bug instructions I tried on OpenJDK/OpenJFX 14ea on WIndows 10 - same.

      A DESCRIPTION OF THE PROBLEM :
      Creating a simple scene with a fill and the fill is overlayed if a javafx.scene.control is INSTANTIATED - it does not need to be added to the scene to cause the issue

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a StackPane with Rectangle and Text objects and place in VBox. Add VBox to scene with a fill e.g. BLUE.
      Add the StackPane to the VBox. Add a mouse click event handler to just Instantiate a javafx.scene.control (e.g. Label)


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Show the stage and all is fine - background is filled BLUE and shows a box with text. Any click will not alter the screen

      ACTUAL -
      When clicking to fire the event the fill is overlayed with a white/grey backround

      ---------- BEGIN SOURCE ----------
      package application;

      import javafx.application.Application;
      import javafx.stage.Stage;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.layout.Background;
      import javafx.scene.layout.BackgroundFill;
      import javafx.scene.layout.StackPane;
      import javafx.scene.layout.VBox;
      import javafx.scene.paint.Color;
      import javafx.scene.shape.Rectangle;
      import javafx.scene.text.Font;
      import javafx.scene.text.Text;

      public class BasicTest extends Application {

      private int count = 0;

      @Override
      public void start(Stage primaryStage) {

      Rectangle r = new Rectangle();
      r.setWidth(200);
      r.setHeight(50);
      r.setFill(Color.BLUE);
      r.setStroke(Color.WHITE);
      r.setStrokeWidth(2);

      Text t = new Text();
              t.setText("Confirm");
              t.setFill(Color.WHITE);
              t.setFont(Font.font("null", 40));

      StackPane sp = new StackPane(r);
      sp.getChildren().add(t);
      sp.setMaxWidth(200);

      t.setTranslateY(-2);
              
      VBox vb = new VBox(sp);

      r.setOnMouseClicked(event -> {
      if (count == 0) new Label();
      else vb.setBackground(new Background(new BackgroundFill(Color.BLUE, null, null)));
      count++;});
              
      Scene scene = new Scene(vb, 300, 200, Color.BLUE);

      primaryStage.setScene(scene);
      primaryStage.show();
      }

      public static void main(String[] args) {
      System.out.println("Start");
      launch(args);
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      There are two workarounds I've found.
      1. Use CSS to set the background colour of the scene:
      .root {
          -fx-background-color: blue;
      }
      2. Add a background colour to the VBox:
      vb.setBackground(new Background(new BackgroundFill(Color.BLUE, null, null)))

      FREQUENCY : always


            kcr Kevin Rushforth
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: