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

Region: css "-fx-background-size" with percents doesn't work properly with background images

XMLWordPrintable

      to reproduce run following code



      import javafx.application.Application;
      import javafx.scene.Parent;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class ButtonBackgroundSize extends Application {

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

          private Parent getContent() {
              VBox list = new VBox(10);
              
              Button but = new Button("Button long long line\n the\n\n\n\n\n\n first line");
              but.setStyle("-fx-background-image: "
                          + "url(\"file:red-rectangle.png\");"+"-fx-background-size: 100% 100%;-fx-border-color: red;");
             
              list.getChildren().add(but);
              return list;
          }

          public void start(Stage stage) {
              stage.setX(100);
              stage.setY(100);
              stage.setWidth(200);
              stage.setHeight(200);
              Scene scene = new Scene(getContent());
              stage.setScene(scene);
              stage.setVisible(true);
          }
      }
      ///////////////////////////////////////




      import javafx.application.Application;
      import javafx.scene.Parent;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class ButtonBackgroundSize extends Application {

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

          private Parent getContent() {
              VBox list = new VBox(10);
              Button but = new Button("Button long long line\n the\n\n\n\n\n\n first line");
              but.setStyle("-fx-background-image: "
                      + "url(\"file:red-rectangle.png\");" + "-fx-background-size: 50%;"
                      + "-fx-background-repeat: no-repeat;");
              list.getChildren().add(but);
              return list;
          }

          public void start(Stage stage) {
              stage.setX(100);
              stage.setY(100);
              stage.setWidth(400);
              stage.setHeight(400);
              Scene scene = new Scene(getContent());
              stage.setScene(scene);
              stage.setVisible(true);
          }
      }
      /////////////////////////////////////////////////


      import java.util.logging.Level;
      import java.util.logging.Logger;
      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.scene.Parent;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class ButtonBackgroundSizeDirtyRegions extends Application {
          Button but;
           VBox list;
          public static void main(String[] args) {
              launch(args);
          }

           private Parent getContent() {
              list = new VBox(10);
              but = new Button("Button long long line\n the\n\n\n\n\n\n first line");
              but.setStyle("-fx-background-image: "
                      + "url(\"file:red-rectangle.png\");" + "-fx-background-size: 300%;"
                      + "-fx-background-repeat: no-repeat;-fx-border-color:green;");
              list.getChildren().add(but);
              return list;
          }

          public void start(Stage stage) {
              stage.setX(100);
              stage.setY(100);
              stage.setWidth(400);
              stage.setHeight(400);
              Scene scene = new Scene(getContent());
              stage.setScene(scene);
              stage.show();
              new Thread(new Runnable(){

                  @Override
                  public void run() {
                      try {
                          Thread.sleep(2000);
                      } catch (InterruptedException ex) {
                          Logger.getLogger(ButtonBackgroundSize.class.getName()).log(Level.SEVERE, null, ex);
                      }
                      Platform.runLater(new Runnable(){

                          @Override
                          public void run() {
                              list.getChildren().remove(but);
                          }
                      });
                  }
              }).start();
          }
      }

        1. ButtonBackgroundSize.java
          1 kB
          Chien Yang
        2. red-rectangle.png
          0.3 kB
          Andrey Nazarov
        3. region.css
          0.4 kB
          Chien Yang
        4. RT-14454-100X100.PNG
          31 kB
          Chien Yang
        5. RT-14454-300X300.PNG
          31 kB
          Chien Yang
        6. RT-14454-50X50-No-Repeat.PNG
          28 kB
          Chien Yang
        7. RT-14454-50X50-Repeat.PNG
          29 kB
          Chien Yang
        8. screenshot-1.jpg
          9 kB
          Andrey Nazarov
        9. screenshot-2.jpg
          14 kB
          Andrey Nazarov
        10. screenshot-3.jpg
          13 kB
          Andrey Nazarov

            ckyang Chien Yang (Inactive)
            anazarov Andrey Nazarov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: