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

Add convenience factory methods for Border and Background

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: openjfx18
    • Component/s: javafx
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      source, binary
    • Compatibility Risk:
      minimal
    • Interface Kind:
      Java API
    • Scope:
      JDK

      Description

      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));
      }

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: