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

Add convenience factory methods for Border and Background

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • jfx18
    • javafx
    • None
    • source, binary
    • minimal
    • Java API
    • JDK

      Summary

      Add convenience methods for creating simple Backgrounds and Borders.

      Problem

      Creating simple Backgrounds and Borders is cumbersome as they require a verbose constructor invocation compared to what is requested from the user.

      Solution

      Add convenience factory methods for the simple cases.

      Specification

      Added to Background:

      /**
       * A convenience factory method for creating a {@code Background} with a single {@code Paint}.
       *
       * @implSpec
       * This call is equivalent to {@link BackgroundFill#BackgroundFill(Paint, CornerRadii, Insets)
       * new Background(new BackgroundFill(fill, null, null));}.
       * @param fill the fill of the background. If {@code null}, {@code Color.TRANSPARENT} will be used.
       * @return a new background of the given fill
       * @since 18
       */
      public static Background fill(Paint fill) {
          return new Background(new BackgroundFill(fill, null, null));
      }

      Added to Border:

      /**
       * A convenience factory method for creating a solid {@code Border} with a single {@code Paint}.
       *
       * @implSpec
       * This call is equivalent to {@link BorderStroke#BorderStroke(Paint, BorderStrokeStyle, CornerRadii, BorderWidths)
       * new Border(new BorderStroke(stroke, BorderStrokeStyle.SOLID, null, null));}.
       * @param stroke the stroke of the border (for all sides). If {@code null}, {@code Color.BLACK} will be used.
       * @return a new border of the given stroke
       * @since 18
       */
      public static Border stroke(Paint stroke) {
          return new Border(new BorderStroke(stroke, BorderStrokeStyle.SOLID, null, null));
      }

            nlisker Nir Lisker
            nlisker Nir Lisker
            Kevin Rushforth
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: