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

FX 8 3D : BackgroundFill with a Color object creates a weird blending result on Windows

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8
    • 8
    • javafx
    • JDK 8.0-b94, Win 7/64b

      A BackgroundFill with a Color object creates a weird blending result, LinearGradient and RadialGradient work fine (Windows only).

      package jiraissue;

      import javafx.animation.Interpolator;
      import javafx.animation.RotateTransition;
      import javafx.animation.Timeline;
      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Group;
      import javafx.scene.PerspectiveCamera;
      import javafx.scene.PointLight;
      import javafx.scene.Scene;
      import javafx.scene.SubScene;
      import javafx.scene.control.RadioButton;
      import javafx.scene.control.ToggleGroup;
      import javafx.scene.layout.Background;
      import javafx.scene.layout.BackgroundFill;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.layout.HBox;
      import javafx.scene.paint.Color;
      import javafx.scene.paint.CycleMethod;
      import javafx.scene.paint.LinearGradient;
      import javafx.scene.paint.PhongMaterial;
      import javafx.scene.paint.Stop;
      import javafx.scene.shape.Cylinder;
      import javafx.scene.transform.Rotate;
      import javafx.stage.Stage;
      import javafx.stage.WindowEvent;
      import javafx.util.Duration;

      public class BackgroundFillBlending extends Application {
          
          public static void main(String[] args) {
              launch(args);
          }
          
          @Override public void start(Stage stage) {
              
              // SubScene
              
              final Group subSceneRoot = new Group();
              final SubScene subScene = new SubScene(subSceneRoot, 800, 800, true, false);
              
              // SubScene's camera
              final PerspectiveCamera perspectiveCamera = new PerspectiveCamera(true);
              perspectiveCamera.setFarClip(25);
              perspectiveCamera.setNearClip(0.1);
              perspectiveCamera.setFieldOfView(44);
              
              subScene.setCamera(perspectiveCamera);
             
              // SubScene's light
              final PointLight pointLight = new PointLight(Color.WHITE);
              pointLight.setTranslateZ(-20000);
                
              // Viewing group: camera and headlight
              final Group viewingGroup = new Group(perspectiveCamera, pointLight);
              viewingGroup.setTranslateZ(-5);
              
              // 3D model
              Cylinder cylinder = new Cylinder();
              cylinder.setMaterial(new PhongMaterial(Color.ORANGE));
              
              final Group cylRotGroup = new Group(cylinder);
              
              final RotateTransition cylRotTransition = new RotateTransition();
              cylRotTransition.setNode(cylRotGroup);
              cylRotTransition.setAxis(Rotate.X_AXIS);
              cylRotTransition.setCycleCount(Timeline.INDEFINITE);
              cylRotTransition.setAutoReverse(false);
              cylRotTransition.setInterpolator(Interpolator.LINEAR);
              cylRotTransition.setByAngle(360);
              cylRotTransition.setDuration(Duration.millis(10000));
             
              subSceneRoot.getChildren().addAll(cylRotGroup, viewingGroup);
              
              // Scene
                              
              // SubScene's parent
              final BorderPane borderPane = new BorderPane();
              borderPane.setMinHeight(0);
              borderPane.setMinWidth(0);

              // Background
              
              final Stop[] stopsLG = new Stop[] {new Stop(0.0, Color.YELLOW),
                                                 new Stop(1.0, Color.LIGHTYELLOW)};
              final LinearGradient lg = new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE, stopsLG);
              
              final Background yellowGradientBG = new Background(new BackgroundFill(lg, null, null));
              final Background yellowColortBG = new Background(new BackgroundFill(Color.YELLOW, null, null));

              final ToggleGroup bgToggleGroup = new ToggleGroup();
              final RadioButton bgColorRadio = new RadioButton("Color");
              final RadioButton bgGradientRadio = new RadioButton("LinearGradient");
              bgColorRadio.setToggleGroup(bgToggleGroup);
              bgGradientRadio.setToggleGroup(bgToggleGroup);
              bgGradientRadio.setSelected(true);
              
              bgColorRadio.setOnAction(new EventHandler<ActionEvent>() {
                  @Override public void handle(ActionEvent e) {
                      borderPane.setBackground(yellowColortBG);
                  }
              });
              bgGradientRadio.setOnAction(new EventHandler<ActionEvent>() {
                  @Override public void handle(ActionEvent e) {
                      borderPane.setBackground(yellowGradientBG);
                  }
              });
              
              borderPane.setBackground(yellowGradientBG);
              
              final HBox radioBox = new HBox();
              radioBox.setSpacing(10);

              radioBox.getChildren().addAll(bgColorRadio, bgGradientRadio);
                         
              borderPane.setCenter(subScene);
              borderPane.setBottom(radioBox);

              final Scene scene = new Scene(borderPane, 900, 900, true);
             
              stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
                  @Override public void handle(WindowEvent event) {
                      System.exit(0);
                  }
              });
              stage.setScene(scene);
              stage.setTitle("BackgroundFillBlending");
              
              stage.show();
              
              cylRotTransition.play();
          }
      }

            ckyang Chien Yang (Inactive)
            alammersdjfx August Lammersdorf (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: