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

Node.snapshot() causes SwingNode to resize

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Version:
    • CPU:
      generic
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :


      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 64bit Professional

      A DESCRIPTION OF THE PROBLEM :
      Calling Node.snapshot() anywhere in the SceneGraph causes an unrelated SwingNode to resize to its preferredSize. The SwingNode in question is in a StackPane which normally stretches it to fit.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the example below and press "Snapshot" button


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Layout should not change, SwingNode should be stretched to fit in StackPane
      ACTUAL -
      SwingNode resized to preferred size.
      If the window is then manually resized it goes back to filling the window.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Color;
      import java.awt.Dimension;

      import javax.swing.JPanel;
      import javax.swing.SwingUtilities;

      import javafx.application.Application;
      import javafx.embed.swing.SwingNode;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;

      public class NodeSnapshotLayoutBug extends Application {

          @Override
          public void start(Stage stage) throws Exception {
              SwingNode swingNode = new SwingNode();
              Button button = new Button("Snapshot");
              button.setOnAction(dave -> {
                  button.snapshot(null, null);
              });
              StackPane stackPane = new StackPane(swingNode);
              Scene scene = new Scene(stackPane);
              stage.setScene(scene);
              stage.show();
              stackPane.getChildren().add(button);

              SwingUtilities.invokeLater(() -> {
                  JPanel rigby = new JPanel();
                  rigby.setPreferredSize(new Dimension(300, 300));
                  rigby.setBackground(Color.red);
                  swingNode.setContent(rigby);
              });
          }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Set a size on the Scene first

        Attachments

          Activity

            People

            • Assignee:
              arapte Ambarish Rapte
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: