kandi background
Explore Kits

WordPress | WordPress subversion repository | Content Management System library

 by   WordPress PHP Version: Current License: Non-SPDX

 by   WordPress PHP Version: Current License: Non-SPDX

Download this library from

kandi X-RAY | WordPress Summary

WordPress is a PHP library typically used in Web Site, Content Management System, Wordpress applications. WordPress has no bugs, it has no vulnerabilities and it has medium support. However WordPress has a Non-SPDX License. You can download it from GitHub.
WordPress started in 2003 with a single bit of code to enhance the typography of everyday writing and with fewer users than you can count on your fingers and toes. Since then it has grown to be the largest self-hosted blogging tool in the world, used on hundreds of thousands of sites and seen by tens of millions of people every day.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • WordPress has a medium active ecosystem.
  • It has 16054 star(s) with 11051 fork(s). There are 1426 watchers for this library.
  • It had no major release in the last 12 months.
  • WordPress has no issues reported. There are no pull requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of WordPress is current.
WordPress Support
Best in #Content Management System
Average in #Content Management System
WordPress Support
Best in #Content Management System
Average in #Content Management System

quality kandi Quality

  • WordPress has 0 bugs and 0 code smells.
WordPress Quality
Best in #Content Management System
Average in #Content Management System
WordPress Quality
Best in #Content Management System
Average in #Content Management System

securitySecurity

  • WordPress has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • WordPress code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
WordPress Security
Best in #Content Management System
Average in #Content Management System
WordPress Security
Best in #Content Management System
Average in #Content Management System

license License

  • WordPress has a Non-SPDX License.
  • Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.
WordPress License
Best in #Content Management System
Average in #Content Management System
WordPress License
Best in #Content Management System
Average in #Content Management System

buildReuse

  • WordPress releases are not available. You will need to build from source code and install.
WordPress Reuse
Best in #Content Management System
Average in #Content Management System
WordPress Reuse
Best in #Content Management System
Average in #Content Management System
Top functions reviewed by kandi - BETA

kandi has reviewed WordPress and discovered the below as its top functions. This is intended to give you an instant insight into WordPress implemented functionality, and help decide if they suit your requirements.

  • Parse an atomically
    • Get the enclosure elements .
      • Parse the ID3 version 2
        • Get posts .
          • Get debug data .
            • Returns the encoding name for the given charset .
              • Performs the multiplication of a scalar .
                • Parse the EML structure
                  • Register theme control panel .
                    • Decode a video file header .

                      Get all kandi verified functions for this library.

                      Get all kandi verified functions for this library.

                      WordPress Key Features

                      WordPress, Git-ified. This repository is just a mirror of the WordPress subversion repository. Please do not send pull requests. Submit pull requests to https://github.com/WordPress/wordpress-develop and patches to https://core.trac.wordpress.org/ instead.

                      Is it possible to add settings to "allow-plugins" in config section in composer.json through the CLI?

                      copy iconCopydownload iconDownload
                      composer config allow-plugins.composer/installers true
                      composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer  true
                      composer config allow-plugins.roots/wordpress-core-installer true
                      
                      composer config --no-interaction allow-plugins.composer/installerstrue
                      composer config --no-interaction allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
                      composer config --no-interaction allow-plugins.roots/wordpress-core-installer true
                      
                      composer config allow-plugins.composer/installers true
                      composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer  true
                      composer config allow-plugins.roots/wordpress-core-installer true
                      
                      composer config --no-interaction allow-plugins.composer/installerstrue
                      composer config --no-interaction allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
                      composer config --no-interaction allow-plugins.roots/wordpress-core-installer true
                      

                      How to get the image links from Gutenberg block gallery and add them as html data attributes to a button in wordpress

                      copy iconCopydownload iconDownload
                      if (has_block("gallery", get_the_content())) 
                      {
                        $post_blocks = parse_blocks(get_the_content());
                        foreach ($post_blocks as $post_block) 
                        {
                          if ("core/gallery" == $post_block["blockName"]) 
                          {
                            $ids = $post_block["attrs"]["ids"];
                          }
                        }
                      }
                      
                      <button class="gallery" 
                      <?php
                      for ($i = 0; $i < count($ids); $i++) {
                        $img_link = wp_get_attachment_image_url($ids[$i], "full");
                        echo "data-img-" . $i . " = " . $img_link . " ";
                      }
                      ?>
                      >
                      Light Box 
                      </button>
                      
                      if (has_block("gallery", get_the_content())) 
                      {
                        $post_blocks = parse_blocks(get_the_content());
                        foreach ($post_blocks as $post_block) 
                        {
                          if ("core/gallery" == $post_block["blockName"]) 
                          {
                            $ids = $post_block["attrs"]["ids"];
                          }
                        }
                      }
                      
                      <button class="gallery" 
                      <?php
                      for ($i = 0; $i < count($ids); $i++) {
                        $img_link = wp_get_attachment_image_url($ids[$i], "full");
                        echo "data-img-" . $i . " = " . $img_link . " ";
                      }
                      ?>
                      >
                      Light Box 
                      </button>
                      

                      jQuery: How to set max height of 3 'h3' element under a specific DIV to all h3 element?

                      copy iconCopydownload iconDownload
                      window.addEventListener("load", function () {
                          matchHeight('[data-mh="match"]');
                      });
                      
                      window.addEventListener("resize", function () {
                          setTimeout(function () {
                              matchHeight('[data-mh="match"]');
                          });
                      });
                      
                      const matchHeight = (element) => {
                          let tallest = 0;
                      
                          const elements = [...document.querySelectorAll(element)];
                      
                          elements.map((el)=> {
                              if (el.offsetHeight > tallest) {
                                  tallest = el.offsetHeight
                              }
                          });
                      
                          elements.map((el)=> {
                              el.style.height = tallest + 'px';
                          });
                      
                      };
                      

                      Woocommerce admin_notices does not work when woocommerce_order_status_changed hook fires

                      copy iconCopydownload iconDownload
                      add_action('woocommerce_order_status_changed', 'test', 99, 4);
                      
                      function test($order_id, $old_status, $new_status, $order_object)
                      {
                        die('You hit the right hook!');
                      }
                      
                      add_action('woocommerce_order_status_changed', 'test', 99, 4);
                      
                      function test($order_id, $old_status, $new_status, $order_object)
                      {
                      
                        if ( $order_object && ($old_status != $new_status) ) 
                        {
                      
                          $notice = 'This notice appears on the order page.';
                      
                          session_start();
                      
                          $_SESSION['your_custom_message_name'] = $notice;
                      
                        }
                      }
                      
                      add_action('admin_notices', 'your_them_displaying_custom_admin_notice');
                      
                      function your_them_displaying_custom_admin_notice()
                      {
                        session_start();
                        if (isset($_SESSION['your_custom_message_name'])) {
                      
                      ?>
                          <div class='notice notice-error is-dismissible'>
                            <p><?php echo $_SESSION['your_custom_message_name'] ?></p>
                          </div>
                      <?php
                          unset($_SESSION['your_custom_message_name']);
                        }
                      }
                      
                      add_action('woocommerce_order_status_changed', 'test', 99, 4);
                      
                      function test($order_id, $old_status, $new_status, $order_object)
                      {
                        die('You hit the right hook!');
                      }
                      
                      add_action('woocommerce_order_status_changed', 'test', 99, 4);
                      
                      function test($order_id, $old_status, $new_status, $order_object)
                      {
                      
                        if ( $order_object && ($old_status != $new_status) ) 
                        {
                      
                          $notice = 'This notice appears on the order page.';
                      
                          session_start();
                      
                          $_SESSION['your_custom_message_name'] = $notice;
                      
                        }
                      }
                      
                      add_action('admin_notices', 'your_them_displaying_custom_admin_notice');
                      
                      function your_them_displaying_custom_admin_notice()
                      {
                        session_start();
                        if (isset($_SESSION['your_custom_message_name'])) {
                      
                      ?>
                          <div class='notice notice-error is-dismissible'>
                            <p><?php echo $_SESSION['your_custom_message_name'] ?></p>
                          </div>
                      <?php
                          unset($_SESSION['your_custom_message_name']);
                        }
                      }
                      

                      Updated windows docker and now it doesn't work outside localhost

                      copy iconCopydownload iconDownload
                      Get-NetIPInterface -AddressFamily IPv4 | Sort-Object -Property InterfaceMetric -Descending
                      
                      // Use this command to make the change for e.g. lets say your 
                      // primary adapter InterfaceAlias is 'Wi-Fi'
                      Set-NetIPInterface -InterfaceAlias 'Wi-Fi' -InterfaceMetric 3
                      
                      Get-NetRoute -AddressFamily IPv4
                      
                      Get-NetIPInterface -AddressFamily IPv4 | Sort-Object -Property InterfaceMetric -Descending
                      
                      // Use this command to make the change for e.g. lets say your 
                      // primary adapter InterfaceAlias is 'Wi-Fi'
                      Set-NetIPInterface -InterfaceAlias 'Wi-Fi' -InterfaceMetric 3
                      
                      Get-NetRoute -AddressFamily IPv4
                      
                      Get-NetIPInterface -AddressFamily IPv4 | Sort-Object -Property InterfaceMetric -Descending
                      
                      // Use this command to make the change for e.g. lets say your 
                      // primary adapter InterfaceAlias is 'Wi-Fi'
                      Set-NetIPInterface -InterfaceAlias 'Wi-Fi' -InterfaceMetric 3
                      
                      Get-NetRoute -AddressFamily IPv4
                      
                      192.168.99.100
                      

                      *why* does list assignment flatten its left hand side?

                      copy iconCopydownload iconDownload
                      my ($first, $second, @rest) = 1..5;
                      .say for $first, $second, @rest;'
                      
                      1
                      2
                      [3 4 5]
                      
                      my ($first, $second, *@rest) := |(1..5);
                      
                      # Process arguments
                      my $proc = Proc::Async.new($program, @some-args, @some-others);
                      
                      # Promise combinators
                      await Promise.anyof(@downloads, @uploads);
                      
                      # File names
                      unlink @temps, @previous-output;
                      
                      # Hash construction
                      my @a = x => 1, y => 2;
                      my @b = z => 3;
                      dd hash @a, @b;  # {:x(1), :y(2), :z(3)}
                      
                      my ($first, $second, @rest) = 1..5;
                      .say for $first, $second, @rest;'
                      
                      1
                      2
                      [3 4 5]
                      
                      my ($first, $second, *@rest) := |(1..5);
                      
                      # Process arguments
                      my $proc = Proc::Async.new($program, @some-args, @some-others);
                      
                      # Promise combinators
                      await Promise.anyof(@downloads, @uploads);
                      
                      # File names
                      unlink @temps, @previous-output;
                      
                      # Hash construction
                      my @a = x => 1, y => 2;
                      my @b = z => 3;
                      dd hash @a, @b;  # {:x(1), :y(2), :z(3)}
                      
                      my ($first, $second, @rest) = 1..5;
                      .say for $first, $second, @rest;'
                      
                      1
                      2
                      [3 4 5]
                      
                      my ($first, $second, *@rest) := |(1..5);
                      
                      # Process arguments
                      my $proc = Proc::Async.new($program, @some-args, @some-others);
                      
                      # Promise combinators
                      await Promise.anyof(@downloads, @uploads);
                      
                      # File names
                      unlink @temps, @previous-output;
                      
                      # Hash construction
                      my @a = x => 1, y => 2;
                      my @b = z => 3;
                      dd hash @a, @b;  # {:x(1), :y(2), :z(3)}
                      
                      my ($first, $second, @rest) = 1..5;
                      .say for $first, $second, @rest;'
                      
                      1
                      2
                      [3 4 5]
                      
                      my ($first, $second, *@rest) := |(1..5);
                      
                      # Process arguments
                      my $proc = Proc::Async.new($program, @some-args, @some-others);
                      
                      # Promise combinators
                      await Promise.anyof(@downloads, @uploads);
                      
                      # File names
                      unlink @temps, @previous-output;
                      
                      # Hash construction
                      my @a = x => 1, y => 2;
                      my @b = z => 3;
                      dd hash @a, @b;  # {:x(1), :y(2), :z(3)}
                      

                      Filtering on an ACF Post Object-field in wordpress in Gatsby and GraphQL

                      copy iconCopydownload iconDownload
                      add_action( 'graphql_register_types', function() {
                          register_graphql_field( 'Page', 'genericPage', [
                              'type'        => 'Integer',
                              'description' => 'generic_page meta value',
                              'resolve'     => function( \WPGraphQL\Model\Post $post ) {
                                  return (int) get_post_meta( $post->databaseId, 'generic_page', true );
                              }
                          ] );
                      });
                      

                      Yin-yang puzzle in Ruby

                      copy iconCopydownload iconDownload
                      yin = (lambda do |cc|
                        print "@"
                        return cc # (3) return Continuation (1)
                      end).call(callcc {|c| c}) # (1) this params call first
                      
                      # (2) lambda will call immediately -> print the first @
                      # so yin = Continuation (1)
                      
                      yang = (lambda do |cc|
                        print "*"
                        return cc # (6) return Continuation (4)
                      end).call(callcc {|c| c}) # (4) this params call first *
                      
                      # (5) lambda will call immediately -> print the first *
                      # so yang = Continuation (4)
                      
                      yin.call(yang)
                      
                      yin = callcc {|c| c} # yin context
                        print '@'
                        yang = callcc {|cc| cc} # yang context
                          print '*'
                          yin.call(yang)
                        # end yang context
                      # end yin context
                      
                      require "continuation"
                      
                      yin = lambda { |yang|
                        cc = callcc { |cc| cc }
                        print "@"
                        yang.call(cc)
                      }
                        
                      yang = lambda { |yin|
                        cc = callcc { |cc| cc }
                        print "*"
                        yin.call(cc)
                      }
                      
                      yin.call(yang)
                      
                      yin = (lambda do |cc|
                        print "@"
                        return cc # (3) return Continuation (1)
                      end).call(callcc {|c| c}) # (1) this params call first
                      
                      # (2) lambda will call immediately -> print the first @
                      # so yin = Continuation (1)
                      
                      yang = (lambda do |cc|
                        print "*"
                        return cc # (6) return Continuation (4)
                      end).call(callcc {|c| c}) # (4) this params call first *
                      
                      # (5) lambda will call immediately -> print the first *
                      # so yang = Continuation (4)
                      
                      yin.call(yang)
                      
                      yin = callcc {|c| c} # yin context
                        print '@'
                        yang = callcc {|cc| cc} # yang context
                          print '*'
                          yin.call(yang)
                        # end yang context
                      # end yin context
                      
                      require "continuation"
                      
                      yin = lambda { |yang|
                        cc = callcc { |cc| cc }
                        print "@"
                        yang.call(cc)
                      }
                        
                      yang = lambda { |yin|
                        cc = callcc { |cc| cc }
                        print "*"
                        yin.call(cc)
                      }
                      
                      yin.call(yang)
                      
                      yin = (lambda do |cc|
                        print "@"
                        return cc # (3) return Continuation (1)
                      end).call(callcc {|c| c}) # (1) this params call first
                      
                      # (2) lambda will call immediately -> print the first @
                      # so yin = Continuation (1)
                      
                      yang = (lambda do |cc|
                        print "*"
                        return cc # (6) return Continuation (4)
                      end).call(callcc {|c| c}) # (4) this params call first *
                      
                      # (5) lambda will call immediately -> print the first *
                      # so yang = Continuation (4)
                      
                      yin.call(yang)
                      
                      yin = callcc {|c| c} # yin context
                        print '@'
                        yang = callcc {|cc| cc} # yang context
                          print '*'
                          yin.call(yang)
                        # end yang context
                      # end yin context
                      
                      require "continuation"
                      
                      yin = lambda { |yang|
                        cc = callcc { |cc| cc }
                        print "@"
                        yang.call(cc)
                      }
                        
                      yang = lambda { |yin|
                        cc = callcc { |cc| cc }
                        print "*"
                        yin.call(cc)
                      }
                      
                      yin.call(yang)
                      

                      Is it possible to align components horizontally when using WrapLayout/FlowLayout?

                      copy iconCopydownload iconDownload
                      cy = y + (height - m.height) / 2;
                      
                      cy = y;
                      
                      public class WrapAndAlignHorizontallyTopLayout implements LayoutManager, java.io.Serializable {
                      
                          /**
                           * This value indicates that each row of components should be left-justified.
                           */
                          public static final int LEFT = 0;
                      
                          /**
                           * This value indicates that each row of components should be centered.
                           */
                          public static final int CENTER = 1;
                      
                          /**
                           * This value indicates that each row of components should be right-justified.
                           */
                          public static final int RIGHT = 2;
                      
                          /**
                           * This value indicates that each row of components should be justified to the
                           * leading edge of the container's orientation, for example, to the left in
                           * left-to-right orientations.
                           *
                           * @see java.awt.Component#getComponentOrientation
                           * @see java.awt.ComponentOrientation
                           * @since 1.2
                           */
                          public static final int LEADING = 3;
                      
                          /**
                           * This value indicates that each row of components should be justified to the
                           * trailing edge of the container's orientation, for example, to the right in
                           * left-to-right orientations.
                           *
                           * @see java.awt.Component#getComponentOrientation
                           * @see java.awt.ComponentOrientation
                           * @since 1.2
                           */
                          public static final int TRAILING = 4;
                      
                          /**
                           * <code>align</code> is the property that determines how each row distributes
                           * empty space. It can be one of the following values:
                           * <ul>
                           * <li><code>LEFT</code>
                           * <li><code>RIGHT</code>
                           * <li><code>CENTER</code>
                           * </ul>
                           *
                           * @serial
                           * @see #getAlignment
                           * @see #setAlignment
                           */
                          int align; // This is for 1.1 serialization compatibility
                      
                          /**
                           * <code>newAlign</code> is the property that determines how each row
                           * distributes empty space for the Java 2 platform, v1.2 and greater. It can be
                           * one of the following three values:
                           * <ul>
                           * <li><code>LEFT</code>
                           * <li><code>RIGHT</code>
                           * <li><code>CENTER</code>
                           * <li><code>LEADING</code>
                           * <li><code>TRAILING</code>
                           * </ul>
                           *
                           * @serial
                           * @since 1.2
                           * @see #getAlignment
                           * @see #setAlignment
                           */
                          int newAlign; // This is the one we actually use
                      
                          /**
                           * The flow layout manager allows a seperation of components with gaps. The
                           * horizontal gap will specify the space between components and between the
                           * components and the borders of the <code>Container</code>.
                           *
                           * @serial
                           * @see #getHgap()
                           * @see #setHgap(int)
                           */
                          int hgap;
                      
                          /**
                           * The flow layout manager allows a seperation of components with gaps. The
                           * vertical gap will specify the space between rows and between the the rows and
                           * the borders of the <code>Container</code>.
                           *
                           * @serial
                           * @see #getHgap()
                           * @see #setHgap(int)
                           */
                          int vgap;
                      
                          /**
                           * If true, components will be aligned on their baseline.
                           */
                          private boolean alignOnBaseline;
                      
                          /*
                           * JDK 1.1 serialVersionUID
                           */
                          private static final long serialVersionUID = -7262534875583282631L;
                      
                          /**
                           * Constructs a new <code>FlowLayout</code> with a centered alignment and a
                           * default 5-unit horizontal and vertical gap.
                           */
                          public WrapAndAlignHorizontallyTopLayout() {
                              this(CENTER, 5, 5);
                          }
                      
                          /**
                           * Constructs a new <code>FlowLayout</code> with the specified alignment and a
                           * default 5-unit horizontal and vertical gap. The value of the alignment
                           * argument must be one of <code>FlowLayout.LEFT</code>,
                           * <code>FlowLayout.RIGHT</code>, <code>FlowLayout.CENTER</code>,
                           * <code>FlowLayout.LEADING</code>, or <code>FlowLayout.TRAILING</code>.
                           * 
                           * @param align the alignment value
                           */
                          public WrapAndAlignHorizontallyTopLayout(int align) {
                              this(align, 5, 5);
                          }
                      
                          /**
                           * Creates a new flow layout manager with the indicated alignment and the
                           * indicated horizontal and vertical gaps.
                           * <p>
                           * The value of the alignment argument must be one of
                           * <code>FlowLayout.LEFT</code>, <code>FlowLayout.RIGHT</code>,
                           * <code>FlowLayout.CENTER</code>, <code>FlowLayout.LEADING</code>, or
                           * <code>FlowLayout.TRAILING</code>.
                           * 
                           * @param align the alignment value
                           * @param hgap  the horizontal gap between components and between the components
                           *              and the borders of the <code>Container</code>
                           * @param vgap  the vertical gap between components and between the components
                           *              and the borders of the <code>Container</code>
                           */
                          public WrapAndAlignHorizontallyTopLayout(int align, int hgap, int vgap) {
                              this.hgap = hgap;
                              this.vgap = vgap;
                              setAlignment(align);
                          }
                      
                          /**
                           * Gets the alignment for this layout. Possible values are
                           * <code>FlowLayout.LEFT</code>, <code>FlowLayout.RIGHT</code>,
                           * <code>FlowLayout.CENTER</code>, <code>FlowLayout.LEADING</code>, or
                           * <code>FlowLayout.TRAILING</code>.
                           * 
                           * @return the alignment value for this layout
                           * @see java.awt.FlowLayout#setAlignment
                           * @since JDK1.1
                           */
                          public int getAlignment() {
                              return newAlign;
                          }
                      
                          /**
                           * Sets the alignment for this layout. Possible values are
                           * <ul>
                           * <li><code>FlowLayout.LEFT</code>
                           * <li><code>FlowLayout.RIGHT</code>
                           * <li><code>FlowLayout.CENTER</code>
                           * <li><code>FlowLayout.LEADING</code>
                           * <li><code>FlowLayout.TRAILING</code>
                           * </ul>
                           * 
                           * @param align one of the alignment values shown above
                           * @see #getAlignment()
                           * @since JDK1.1
                           */
                          public void setAlignment(int align) {
                              this.newAlign = align;
                      
                              // this.align is used only for serialization compatibility,
                              // so set it to a value compatible with the 1.1 version
                              // of the class
                      
                              switch (align) {
                              case LEADING:
                                  this.align = LEFT;
                                  break;
                              case TRAILING:
                                  this.align = RIGHT;
                                  break;
                              default:
                                  this.align = align;
                                  break;
                              }
                          }
                      
                          /**
                           * Gets the horizontal gap between components and between the components and the
                           * borders of the <code>Container</code>
                           *
                           * @return the horizontal gap between components and between the components and
                           *         the borders of the <code>Container</code>
                           * @see java.awt.FlowLayout#setHgap
                           * @since JDK1.1
                           */
                          public int getHgap() {
                              return hgap;
                          }
                      
                          /**
                           * Sets the horizontal gap between components and between the components and the
                           * borders of the <code>Container</code>.
                           *
                           * @param hgap the horizontal gap between components and between the components
                           *             and the borders of the <code>Container</code>
                           * @see java.awt.FlowLayout#getHgap
                           * @since JDK1.1
                           */
                          public void setHgap(int hgap) {
                              this.hgap = hgap;
                          }
                      
                          /**
                           * Gets the vertical gap between components and between the components and the
                           * borders of the <code>Container</code>.
                           *
                           * @return the vertical gap between components and between the components and
                           *         the borders of the <code>Container</code>
                           * @see java.awt.FlowLayout#setVgap
                           * @since JDK1.1
                           */
                          public int getVgap() {
                              return vgap;
                          }
                      
                          /**
                           * Sets the vertical gap between components and between the components and the
                           * borders of the <code>Container</code>.
                           *
                           * @param vgap the vertical gap between components and between the components
                           *             and the borders of the <code>Container</code>
                           * @see java.awt.FlowLayout#getVgap
                           * @since JDK1.1
                           */
                          public void setVgap(int vgap) {
                              this.vgap = vgap;
                          }
                      
                          /**
                           * Sets whether or not components should be vertically aligned along their
                           * baseline. Components that do not have a baseline will be centered. The
                           * default is false.
                           *
                           * @param alignOnBaseline whether or not components should be vertically aligned
                           *                        on their baseline
                           * @since 1.6
                           */
                          public void setAlignOnBaseline(boolean alignOnBaseline) {
                              this.alignOnBaseline = alignOnBaseline;
                          }
                      
                          /**
                           * Returns true if components are to be vertically aligned along their baseline.
                           * The default is false.
                           *
                           * @return true if components are to be vertically aligned along their baseline
                           * @since 1.6
                           */
                          public boolean getAlignOnBaseline() {
                              return alignOnBaseline;
                          }
                      
                          /**
                           * Adds the specified component to the layout. Not used by this class.
                           * 
                           * @param name the name of the component
                           * @param comp the component to be added
                           */
                          @Override
                          public void addLayoutComponent(String name, Component comp) {
                          }
                      
                          /**
                           * Removes the specified component from the layout. Not used by this class.
                           * 
                           * @param comp the component to remove
                           * @see java.awt.Container#removeAll
                           */
                          @Override
                          public void removeLayoutComponent(Component comp) {
                          }
                      
                          /**
                           * Returns the preferred dimensions for this layout given the <i>visible</i>
                           * components in the specified target container.
                           * 
                           * @param target the component which needs to be laid out
                           * @return the preferred dimensions to lay out the subcomponents of the
                           *         specified container
                           */
                          @Override
                          public Dimension preferredLayoutSize(Container target) {
                              return layoutSize(target, true);
                          }
                      
                          /**
                           * Returns the minimum dimensions needed to layout the <i>visible</i> components
                           * contained in the specified target container.
                           * 
                           * @param target the component which needs to be laid out
                           * @return the minimum dimensions to lay out the subcomponents of the specified
                           *         container
                           */
                          @Override
                          public Dimension minimumLayoutSize(Container target) {
                              Dimension minimum = layoutSize(target, false);
                              minimum.width -= (getHgap() + 1);
                              return minimum;
                          }
                      
                          /**
                           * Returns the minimum or preferred dimension needed to layout the target
                           * container.
                           *
                           * @param target    target to get layout size for
                           * @param preferred should preferred size be calculated
                           * @return the dimension to layout the target container
                           */
                          private Dimension layoutSize(Container target, boolean preferred) {
                              synchronized (target.getTreeLock()) {
                                  // Each row must fit with the width allocated to the containter.
                                  // When the container width = 0, the preferred width of the container
                                  // has not yet been calculated so lets ask for the maximum.
                      
                                  int targetWidth = target.getSize().width;
                                  Container container = target;
                      
                                  while (container.getSize().width == 0 && container.getParent() != null) {
                                      container = container.getParent();
                                  }
                      
                                  targetWidth = container.getSize().width;
                      
                                  if (targetWidth == 0)
                                      targetWidth = Integer.MAX_VALUE;
                      
                                  int hgap = getHgap();
                                  int vgap = getVgap();
                                  Insets insets = target.getInsets();
                                  int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
                                  int maxWidth = targetWidth - horizontalInsetsAndGap;
                      
                                  // Fit components into the allowed width
                      
                                  Dimension dim = new Dimension(0, 0);
                                  int rowWidth = 0;
                                  int rowHeight = 0;
                      
                                  int nmembers = target.getComponentCount();
                      
                                  for (int i = 0; i < nmembers; i++) {
                                      Component m = target.getComponent(i);
                      
                                      if (m.isVisible()) {
                                          Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
                      
                                          // Can't add the component to current row. Start a new row.
                      
                                          if (rowWidth + d.width > maxWidth) {
                                              addRow(dim, rowWidth, rowHeight);
                                              rowWidth = 0;
                                              rowHeight = 0;
                                          }
                      
                                          // Add a horizontal gap for all components after the first
                      
                                          if (rowWidth != 0) {
                                              rowWidth += hgap;
                                          }
                      
                                          rowWidth += d.width;
                                          rowHeight = Math.max(rowHeight, d.height);
                                      }
                                  }
                      
                                  addRow(dim, rowWidth, rowHeight);
                      
                                  dim.width += horizontalInsetsAndGap;
                                  dim.height += insets.top + insets.bottom + vgap * 2;
                      
                                  // When using a scroll pane or the DecoratedLookAndFeel we need to
                                  // make sure the preferred size is less than the size of the
                                  // target containter so shrinking the container size works
                                  // correctly. Removing the horizontal gap is an easy way to do this.
                      
                                  Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
                      
                                  if (scrollPane != null && target.isValid()) {
                                      dim.width -= (hgap + 1);
                                  }
                      
                                  return dim;
                              }
                          }
                      
                          /*
                           * A new row has been completed. Use the dimensions of this row to update the
                           * preferred size for the container.
                           *
                           * @param dim update the width and height when appropriate
                           * 
                           * @param rowWidth the width of the row to add
                           * 
                           * @param rowHeight the height of the row to add
                           */
                          private void addRow(Dimension dim, int rowWidth, int rowHeight) {
                              dim.width = Math.max(dim.width, rowWidth);
                      
                              if (dim.height > 0) {
                                  dim.height += getVgap();
                              }
                      
                              dim.height += rowHeight;
                          }
                      
                          /**
                           * Centers the elements in the specified row, if there is any slack.
                           * 
                           * @param target      the component which needs to be moved
                           * @param x           the x coordinate
                           * @param y           the y coordinate
                           * @param width       the width dimensions
                           * @param height      the height dimensions
                           * @param rowStart    the beginning of the row
                           * @param rowEnd      the the ending of the row
                           * @param useBaseline Whether or not to align on baseline.
                           * @param ascent      Ascent for the components. This is only valid if
                           *                    useBaseline is true.
                           * @param descent     Ascent for the components. This is only valid if
                           *                    useBaseline is true.
                           * @return actual row height
                           */
                          private int moveComponents(Container target, int x, int y, int width, int height, int rowStart, int rowEnd,
                                  boolean ltr, boolean useBaseline, int[] ascent, int[] descent) {
                              switch (newAlign) {
                              case LEFT:
                                  x += ltr ? 0 : width;
                                  break;
                              case CENTER:
                                  x += width / 2;
                                  break;
                              case RIGHT:
                                  x += ltr ? width : 0;
                                  break;
                              case LEADING:
                                  break;
                              case TRAILING:
                                  x += width;
                                  break;
                              }
                              int maxAscent = 0;
                              int nonbaselineHeight = 0;
                              int baselineOffset = 0;
                              if (useBaseline) {
                                  int maxDescent = 0;
                                  for (int i = rowStart; i < rowEnd; i++) {
                                      Component m = target.getComponent(i);
                                      if (m.isVisible()) {
                                          if (ascent[i] >= 0) {
                                              maxAscent = Math.max(maxAscent, ascent[i]);
                                              maxDescent = Math.max(maxDescent, descent[i]);
                                          } else {
                                              nonbaselineHeight = Math.max(m.getHeight(), nonbaselineHeight);
                                          }
                                      }
                                  }
                                  height = Math.max(maxAscent + maxDescent, nonbaselineHeight);
                                  baselineOffset = (height - maxAscent - maxDescent) / 2;
                              }
                              for (int i = rowStart; i < rowEnd; i++) {
                                  Component m = target.getComponent(i);
                                  if (m.isVisible()) {
                                      int cy;
                                      if (useBaseline && ascent[i] >= 0) {
                                          cy = y + baselineOffset + maxAscent - ascent[i];
                                      } else {
                                          cy = y;
                                      }
                                      if (ltr) {
                                          m.setLocation(x, cy);
                                      } else {
                                          m.setLocation(target.getWidth() - x - m.getWidth(), cy);
                                      }
                                      x += m.getWidth() + hgap;
                                  }
                              }
                              return height;
                          }
                      
                          /**
                           * Lays out the container. This method lets each <i>visible</i> component take
                           * its preferred size by reshaping the components in the target container in
                           * order to satisfy the alignment of this <code>FlowLayout</code> object.
                           *
                           * @param target the specified component being laid out
                           * @see Container
                           * @see java.awt.Container#doLayout
                           */
                          @Override
                          public void layoutContainer(Container target) {
                              synchronized (target.getTreeLock()) {
                                  Insets insets = target.getInsets();
                                  int maxwidth = target.getWidth() - (insets.left + insets.right + hgap * 2);
                                  int nmembers = target.getComponentCount();
                                  int x = 0, y = insets.top + vgap;
                                  int rowh = 0, start = 0;
                      
                                  boolean ltr = target.getComponentOrientation().isLeftToRight();
                      
                                  boolean useBaseline = getAlignOnBaseline();
                                  int[] ascent = null;
                                  int[] descent = null;
                      
                                  if (useBaseline) {
                                      ascent = new int[nmembers];
                                      descent = new int[nmembers];
                                  }
                      
                                  for (int i = 0; i < nmembers; i++) {
                                      Component m = target.getComponent(i);
                                      if (m.isVisible()) {
                                          Dimension d = m.getPreferredSize();
                                          m.setSize(d.width, d.height);
                      
                                          if (useBaseline) {
                                              int baseline = m.getBaseline(d.width, d.height);
                                              if (baseline >= 0) {
                                                  ascent[i] = baseline;
                                                  descent[i] = d.height - baseline;
                                              } else {
                                                  ascent[i] = -1;
                                              }
                                          }
                                          if ((x == 0) || ((x + d.width) <= maxwidth)) {
                                              if (x > 0) {
                                                  x += hgap;
                                              }
                                              x += d.width;
                                              rowh = Math.max(rowh, d.height);
                                          } else {
                                              rowh = moveComponents(target, insets.left + hgap, y, maxwidth - x, rowh, start, i, ltr,
                                                      useBaseline, ascent, descent);
                                              x = d.width;
                                              y += vgap + rowh;
                                              rowh = d.height;
                                              start = i;
                                          }
                                      }
                                  }
                                  moveComponents(target, insets.left + hgap, y, maxwidth - x, rowh, start, nmembers, ltr, useBaseline, ascent,
                                          descent);
                              }
                          }
                      
                          //
                          // the internal serial version which says which version was written
                          // - 0 (default) for versions before the Java 2 platform, v1.2
                          // - 1 for version >= Java 2 platform v1.2, which includes "newAlign" field
                          //
                          private static final int currentSerialVersion = 1;
                          /**
                           * This represent the <code>currentSerialVersion</code> which is bein used. It
                           * will be one of two values : <code>0</code> versions before Java 2 platform
                           * v1.2.. <code>1</code> versions after Java 2 platform v1.2..
                           *
                           * @serial
                           * @since 1.2
                           */
                          private int serialVersionOnStream = currentSerialVersion;
                      
                          /**
                           * Reads this object out of a serialization stream, handling objects written by
                           * older versions of the class that didn't contain all of the fields we use
                           * now..
                           */
                          private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
                              stream.defaultReadObject();
                      
                              if (serialVersionOnStream < 1) {
                                  // "newAlign" field wasn't present, so use the old "align" field.
                                  setAlignment(this.align);
                              }
                              serialVersionOnStream = currentSerialVersion;
                          }
                      
                          /**
                           * Returns a string representation of this <code>FlowLayout</code> object and
                           * its values.
                           * 
                           * @return a string representation of this layout
                           */
                          @Override
                          public String toString() {
                              String str = "";
                              switch (align) {
                              case LEFT:
                                  str = ",align=left";
                                  break;
                              case CENTER:
                                  str = ",align=center";
                                  break;
                              case RIGHT:
                                  str = ",align=right";
                                  break;
                              case LEADING:
                                  str = ",align=leading";
                                  break;
                              case TRAILING:
                                  str = ",align=trailing";
                                  break;
                              }
                              return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + str + "]";
                          }
                      
                      }
                      
                      public class WrapLayoutExample {
                          public static void main(String[] args) {
                              SwingUtilities.invokeLater(WrapLayoutExample::runGui);
                          }
                      
                          private static void runGui() {
                              JFrame frame = new JFrame("A");
                              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      
                              JPanel panel = new JPanel(new WrapAndAlignHorizontallyTopLayout());
                      
                              JLabel l = new JLabel("CCC");
                              l.setBorder(BorderFactory.createLineBorder(Color.red, 10));
                              l.setVerticalAlignment(JLabel.TOP);
                      
                              panel.add(l);
                      
                              for (int i = 0; i < 44; i++) {
                                  l = new JLabel("BBBB");
                                  l.setBorder(BorderFactory.createLineBorder(Color.red, (int) (Math.random() * 50)));
                                  panel.add(l);
                              }
                      
                              frame.setSize(300, 300);
                              frame.setLayout(new BorderLayout());
                              frame.add(new JScrollPane(panel));
                              frame.setVisible(true);
                          }
                      }
                      
                      cy = y + (height - m.height) / 2;
                      
                      cy = y;
                      
                      public class WrapAndAlignHorizontallyTopLayout implements LayoutManager, java.io.Serializable {
                      
                          /**
                           * This value indicates that each row of components should be left-justified.
                           */
                          public static final int LEFT = 0;
                      
                          /**
                           * This value indicates that each row of components should be centered.
                           */
                          public static final int CENTER = 1;
                      
                          /**
                           * This value indicates that each row of components should be right-justified.
                           */
                          public static final int RIGHT = 2;
                      
                          /**
                           * This value indicates that each row of components should be justified to the
                           * leading edge of the container's orientation, for example, to the left in
                           * left-to-right orientations.
                           *
                           * @see java.awt.Component#getComponentOrientation
                           * @see java.awt.ComponentOrientation
                           * @since 1.2
                           */
                          public static final int LEADING = 3;
                      
                          /**
                           * This value indicates that each row of components should be justified to the
                           * trailing edge of the container's orientation, for example, to the right in
                           * left-to-right orientations.
                           *
                           * @see java.awt.Component#getComponentOrientation
                           * @see java.awt.ComponentOrientation
                           * @since 1.2
                           */
                          public static final int TRAILING = 4;
                      
                          /**
                           * <code>align</code> is the property that determines how each row distributes
                           * empty space. It can be one of the following values:
                           * <ul>
                           * <li><code>LEFT</code>
                           * <li><code>RIGHT</code>
                           * <li><code>CENTER</code>
                           * </ul>
                           *
                           * @serial
                           * @see #getAlignment
                           * @see #setAlignment
                           */
                          int align; // This is for 1.1 serialization compatibility
                      
                          /**
                           * <code>newAlign</code> is the property that determines how each row
                           * distributes empty space for the Java 2 platform, v1.2 and greater. It can be
                           * one of the following three values:
                           * <ul>
                           * <li><code>LEFT</code>
                           * <li><code>RIGHT</code>
                           * <li><code>CENTER</code>
                           * <li><code>LEADING</code>
                           * <li><code>TRAILING</code>
                           * </ul>
                           *
                           * @serial
                           * @since 1.2
                           * @see #getAlignment
                           * @see #setAlignment
                           */
                          int newAlign; // This is the one we actually use
                      
                          /**
                           * The flow layout manager allows a seperation of components with gaps. The
                           * horizontal gap will specify the space between components and between the
                           * components and the borders of the <code>Container</code>.
                           *
                           * @serial
                           * @see #getHgap()
                           * @see #setHgap(int)
                           */
                          int hgap;
                      
                          /**
                           * The flow layout manager allows a seperation of components with gaps. The
                           * vertical gap will specify the space between rows and between the the rows and
                           * the borders of the <code>Container</code>.
                           *
                           * @serial
                           * @see #getHgap()
                           * @see #setHgap(int)
                           */
                          int vgap;
                      
                          /**
                           * If true, components will be aligned on their baseline.
                           */
                          private boolean alignOnBaseline;
                      
                          /*
                           * JDK 1.1 serialVersionUID
                           */
                          private static final long serialVersionUID = -7262534875583282631L;
                      
                          /**
                           * Constructs a new <code>FlowLayout</code> with a centered alignment and a
                           * default 5-unit horizontal and vertical gap.
                           */
                          public WrapAndAlignHorizontallyTopLayout() {
                              this(CENTER, 5, 5);
                          }
                      
                          /**
                           * Constructs a new <code>FlowLayout</code> with the specified alignment and a
                           * default 5-unit horizontal and vertical gap. The value of the alignment
                           * argument must be one of <code>FlowLayout.LEFT</code>,
                           * <code>FlowLayout.RIGHT</code>, <code>FlowLayout.CENTER</code>,
                           * <code>FlowLayout.LEADING</code>, or <code>FlowLayout.TRAILING</code>.
                           * 
                           * @param align the alignment value
                           */
                          public WrapAndAlignHorizontallyTopLayout(int align) {
                              this(align, 5, 5);
                          }
                      
                          /**
                           * Creates a new flow layout manager with the indicated alignment and the
                           * indicated horizontal and vertical gaps.
                           * <p>
                           * The value of the alignment argument must be one of
                           * <code>FlowLayout.LEFT</code>, <code>FlowLayout.RIGHT</code>,
                           * <code>FlowLayout.CENTER</code>, <code>FlowLayout.LEADING</code>, or
                           * <code>FlowLayout.TRAILING</code>.
                           * 
                           * @param align the alignment value
                           * @param hgap  the horizontal gap between components and between the components
                           *              and the borders of the <code>Container</code>
                           * @param vgap  the vertical gap between components and between the components
                           *              and the borders of the <code>Container</code>
                           */
                          public WrapAndAlignHorizontallyTopLayout(int align, int hgap, int vgap) {
                              this.hgap = hgap;
                              this.vgap = vgap;
                              setAlignment(align);
                          }
                      
                          /**
                           * Gets the alignment for this layout. Possible values are
                           * <code>FlowLayout.LEFT</code>, <code>FlowLayout.RIGHT</code>,
                           * <code>FlowLayout.CENTER</code>, <code>FlowLayout.LEADING</code>, or
                           * <code>FlowLayout.TRAILING</code>.
                           * 
                           * @return the alignment value for this layout
                           * @see java.awt.FlowLayout#setAlignment
                           * @since JDK1.1
                           */
                          public int getAlignment() {
                              return newAlign;
                          }
                      
                          /**
                           * Sets the alignment for this layout. Possible values are
                           * <ul>
                           * <li><code>FlowLayout.LEFT</code>
                           * <li><code>FlowLayout.RIGHT</code>
                           * <li><code>FlowLayout.CENTER</code>
                           * <li><code>FlowLayout.LEADING</code>
                           * <li><code>FlowLayout.TRAILING</code>
                           * </ul>
                           * 
                           * @param align one of the alignment values shown above
                           * @see #getAlignment()
                           * @since JDK1.1
                           */
                          public void setAlignment(int align) {
                              this.newAlign = align;
                      
                              // this.align is used only for serialization compatibility,
                              // so set it to a value compatible with the 1.1 version
                              // of the class
                      
                              switch (align) {
                              case LEADING:
                                  this.align = LEFT;
                                  break;
                              case TRAILING:
                                  this.align = RIGHT;
                                  break;
                              default:
                                  this.align = align;
                                  break;
                              }
                          }
                      
                          /**
                           * Gets the horizontal gap between components and between the components and the
                           * borders of the <code>Container</code>
                           *
                           * @return the horizontal gap between components and between the components and
                           *         the borders of the <code>Container</code>
                           * @see java.awt.FlowLayout#setHgap
                           * @since JDK1.1
                           */
                          public int getHgap() {
                              return hgap;
                          }
                      
                          /**
                           * Sets the horizontal gap between components and between the components and the
                           * borders of the <code>Container</code>.
                           *
                           * @param hgap the horizontal gap between components and between the components
                           *             and the borders of the <code>Container</code>
                           * @see java.awt.FlowLayout#getHgap
                           * @since JDK1.1
                           */
                          public void setHgap(int hgap) {
                              this.hgap = hgap;
                          }
                      
                          /**
                           * Gets the vertical gap between components and between the components and the
                           * borders of the <code>Container</code>.
                           *
                           * @return the vertical gap between components and between the components and
                           *         the borders of the <code>Container</code>
                           * @see java.awt.FlowLayout#setVgap
                           * @since JDK1.1
                           */
                          public int getVgap() {
                              return vgap;
                          }
                      
                          /**
                           * Sets the vertical gap between components and between the components and the
                           * borders of the <code>Container</code>.
                           *
                           * @param vgap the vertical gap between components and between the components
                           *             and the borders of the <code>Container</code>
                           * @see java.awt.FlowLayout#getVgap
                           * @since JDK1.1
                           */
                          public void setVgap(int vgap) {
                              this.vgap = vgap;
                          }
                      
                          /**
                           * Sets whether or not components should be vertically aligned along their
                           * baseline. Components that do not have a baseline will be centered. The
                           * default is false.
                           *
                           * @param alignOnBaseline whether or not components should be vertically aligned
                           *                        on their baseline
                           * @since 1.6
                           */
                          public void setAlignOnBaseline(boolean alignOnBaseline) {
                              this.alignOnBaseline = alignOnBaseline;
                          }
                      
                          /**
                           * Returns true if components are to be vertically aligned along their baseline.
                           * The default is false.
                           *
                           * @return true if components are to be vertically aligned along their baseline
                           * @since 1.6
                           */
                          public boolean getAlignOnBaseline() {
                              return alignOnBaseline;
                          }
                      
                          /**
                           * Adds the specified component to the layout. Not used by this class.
                           * 
                           * @param name the name of the component
                           * @param comp the component to be added
                           */
                          @Override
                          public void addLayoutComponent(String name, Component comp) {
                          }
                      
                          /**
                           * Removes the specified component from the layout. Not used by this class.
                           * 
                           * @param comp the component to remove
                           * @see java.awt.Container#removeAll
                           */
                          @Override
                          public void removeLayoutComponent(Component comp) {
                          }
                      
                          /**
                           * Returns the preferred dimensions for this layout given the <i>visible</i>
                           * components in the specified target container.
                           * 
                           * @param target the component which needs to be laid out
                           * @return the preferred dimensions to lay out the subcomponents of the
                           *         specified container
                           */
                          @Override
                          public Dimension preferredLayoutSize(Container target) {
                              return layoutSize(target, true);
                          }
                      
                          /**
                           * Returns the minimum dimensions needed to layout the <i>visible</i> components
                           * contained in the specified target container.
                           * 
                           * @param target the component which needs to be laid out
                           * @return the minimum dimensions to lay out the subcomponents of the specified
                           *         container
                           */
                          @Override
                          public Dimension minimumLayoutSize(Container target) {
                              Dimension minimum = layoutSize(target, false);
                              minimum.width -= (getHgap() + 1);
                              return minimum;
                          }
                      
                          /**
                           * Returns the minimum or preferred dimension needed to layout the target
                           * container.
                           *
                           * @param target    target to get layout size for
                           * @param preferred should preferred size be calculated
                           * @return the dimension to layout the target container
                           */
                          private Dimension layoutSize(Container target, boolean preferred) {
                              synchronized (target.getTreeLock()) {
                                  // Each row must fit with the width allocated to the containter.
                                  // When the container width = 0, the preferred width of the container
                                  // has not yet been calculated so lets ask for the maximum.
                      
                                  int targetWidth = target.getSize().width;
                                  Container container = target;
                      
                                  while (container.getSize().width == 0 && container.getParent() != null) {
                                      container = container.getParent();
                                  }
                      
                                  targetWidth = container.getSize().width;
                      
                                  if (targetWidth == 0)
                                      targetWidth = Integer.MAX_VALUE;
                      
                                  int hgap = getHgap();
                                  int vgap = getVgap();
                                  Insets insets = target.getInsets();
                                  int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
                                  int maxWidth = targetWidth - horizontalInsetsAndGap;
                      
                                  // Fit components into the allowed width
                      
                                  Dimension dim = new Dimension(0, 0);
                                  int rowWidth = 0;
                                  int rowHeight = 0;
                      
                                  int nmembers = target.getComponentCount();
                      
                                  for (int i = 0; i < nmembers; i++) {
                                      Component m = target.getComponent(i);
                      
                                      if (m.isVisible()) {
                                          Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
                      
                                          // Can't add the component to current row. Start a new row.
                      
                                          if (rowWidth + d.width > maxWidth) {
                                              addRow(dim, rowWidth, rowHeight);
                                              rowWidth = 0;
                                              rowHeight = 0;
                                          }
                      
                                          // Add a horizontal gap for all components after the first
                      
                                          if (rowWidth != 0) {
                                              rowWidth += hgap;
                                          }
                      
                                          rowWidth += d.width;
                                          rowHeight = Math.max(rowHeight, d.height);
                                      }
                                  }
                      
                                  addRow(dim, rowWidth, rowHeight);
                      
                                  dim.width += horizontalInsetsAndGap;
                                  dim.height += insets.top + insets.bottom + vgap * 2;
                      
                                  // When using a scroll pane or the DecoratedLookAndFeel we need to
                                  // make sure the preferred size is less than the size of the
                                  // target containter so shrinking the container size works
                                  // correctly. Removing the horizontal gap is an easy way to do this.
                      
                                  Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
                      
                                  if (scrollPane != null && target.isValid()) {
                                      dim.width -= (hgap + 1);
                                  }
                      
                                  return dim;
                              }
                          }
                      
                          /*
                           * A new row has been completed. Use the dimensions of this row to update the
                           * preferred size for the container.
                           *
                           * @param dim update the width and height when appropriate
                           * 
                           * @param rowWidth the width of the row to add
                           * 
                           * @param rowHeight the height of the row to add
                           */
                          private void addRow(Dimension dim, int rowWidth, int rowHeight) {
                              dim.width = Math.max(dim.width, rowWidth);
                      
                              if (dim.height > 0) {
                                  dim.height += getVgap();
                              }
                      
                              dim.height += rowHeight;
                          }
                      
                          /**
                           * Centers the elements in the specified row, if there is any slack.
                           * 
                           * @param target      the component which needs to be moved
                           * @param x           the x coordinate
                           * @param y           the y coordinate
                           * @param width       the width dimensions
                           * @param height      the height dimensions
                           * @param rowStart    the beginning of the row
                           * @param rowEnd      the the ending of the row
                           * @param useBaseline Whether or not to align on baseline.
                           * @param ascent      Ascent for the components. This is only valid if
                           *                    useBaseline is true.
                           * @param descent     Ascent for the components. This is only valid if
                           *                    useBaseline is true.
                           * @return actual row height
                           */
                          private int moveComponents(Container target, int x, int y, int width, int height, int rowStart, int rowEnd,
                                  boolean ltr, boolean useBaseline, int[] ascent, int[] descent) {
                              switch (newAlign) {
                              case LEFT:
                                  x += ltr ? 0 : width;
                                  break;
                              case CENTER:
                                  x += width / 2;
                                  break;
                              case RIGHT:
                                  x += ltr ? width : 0;
                                  break;
                              case LEADING:
                                  break;
                              case TRAILING:
                                  x += width;
                                  break;
                              }
                              int maxAscent = 0;
                              int nonbaselineHeight = 0;
                              int baselineOffset = 0;
                              if (useBaseline) {
                                  int maxDescent = 0;
                                  for (int i = rowStart; i < rowEnd; i++) {
                                      Component m = target.getComponent(i);
                                      if (m.isVisible()) {
                                          if (ascent[i] >= 0) {
                                              maxAscent = Math.max(maxAscent, ascent[i]);
                                              maxDescent = Math.max(maxDescent, descent[i]);
                                          } else {
                                              nonbaselineHeight = Math.max(m.getHeight(), nonbaselineHeight);
                                          }
                                      }
                                  }
                                  height = Math.max(maxAscent + maxDescent, nonbaselineHeight);
                                  baselineOffset = (height - maxAscent - maxDescent) / 2;
                              }
                              for (int i = rowStart; i < rowEnd; i++) {
                                  Component m = target.getComponent(i);
                                  if (m.isVisible()) {
                                      int cy;
                                      if (useBaseline && ascent[i] >= 0) {
                                          cy = y + baselineOffset + maxAscent - ascent[i];
                                      } else {
                                          cy = y;
                                      }
                                      if (ltr) {
                                          m.setLocation(x, cy);
                                      } else {
                                          m.setLocation(target.getWidth() - x - m.getWidth(), cy);
                                      }
                                      x += m.getWidth() + hgap;
                                  }
                              }
                              return height;
                          }
                      
                          /**
                           * Lays out the container. This method lets each <i>visible</i> component take
                           * its preferred size by reshaping the components in the target container in
                           * order to satisfy the alignment of this <code>FlowLayout</code> object.
                           *
                           * @param target the specified component being laid out
                           * @see Container
                           * @see java.awt.Container#doLayout
                           */
                          @Override
                          public void layoutContainer(Container target) {
                              synchronized (target.getTreeLock()) {
                                  Insets insets = target.getInsets();
                                  int maxwidth = target.getWidth() - (insets.left + insets.right + hgap * 2);
                                  int nmembers = target.getComponentCount();
                                  int x = 0, y = insets.top + vgap;
                                  int rowh = 0, start = 0;
                      
                                  boolean ltr = target.getComponentOrientation().isLeftToRight();
                      
                                  boolean useBaseline = getAlignOnBaseline();
                                  int[] ascent = null;
                                  int[] descent = null;
                      
                                  if (useBaseline) {
                                      ascent = new int[nmembers];
                                      descent = new int[nmembers];
                                  }
                      
                                  for (int i = 0; i < nmembers; i++) {
                                      Component m = target.getComponent(i);
                                      if (m.isVisible()) {
                                          Dimension d = m.getPreferredSize();
                                          m.setSize(d.width, d.height);
                      
                                          if (useBaseline) {
                                              int baseline = m.getBaseline(d.width, d.height);
                                              if (baseline >= 0) {
                                                  ascent[i] = baseline;
                                                  descent[i] = d.height - baseline;
                                              } else {
                                                  ascent[i] = -1;
                                              }
                                          }
                                          if ((x == 0) || ((x + d.width) <= maxwidth)) {
                                              if (x > 0) {
                                                  x += hgap;
                                              }
                                              x += d.width;
                                              rowh = Math.max(rowh, d.height);
                                          } else {
                                              rowh = moveComponents(target, insets.left + hgap, y, maxwidth - x, rowh, start, i, ltr,
                                                      useBaseline, ascent, descent);
                                              x = d.width;
                                              y += vgap + rowh;
                                              rowh = d.height;
                                              start = i;
                                          }
                                      }
                                  }
                                  moveComponents(target, insets.left + hgap, y, maxwidth - x, rowh, start, nmembers, ltr, useBaseline, ascent,
                                          descent);
                              }
                          }
                      
                          //
                          // the internal serial version which says which version was written
                          // - 0 (default) for versions before the Java 2 platform, v1.2
                          // - 1 for version >= Java 2 platform v1.2, which includes "newAlign" field
                          //
                          private static final int currentSerialVersion = 1;
                          /**
                           * This represent the <code>currentSerialVersion</code> which is bein used. It
                           * will be one of two values : <code>0</code> versions before Java 2 platform
                           * v1.2.. <code>1</code> versions after Java 2 platform v1.2..
                           *
                           * @serial
                           * @since 1.2
                           */
                          private int serialVersionOnStream = currentSerialVersion;
                      
                          /**
                           * Reads this object out of a serialization stream, handling objects written by
                           * older versions of the class that didn't contain all of the fields we use
                           * now..
                           */
                          private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
                              stream.defaultReadObject();
                      
                              if (serialVersionOnStream < 1) {
                                  // "newAlign" field wasn't present, so use the old "align" field.
                                  setAlignment(this.align);
                              }
                              serialVersionOnStream = currentSerialVersion;
                          }
                      
                          /**
                           * Returns a string representation of this <code>FlowLayout</code> object and
                           * its values.
                           * 
                           * @return a string representation of this layout
                           */
                          @Override
                          public String toString() {
                              String str = "";
                              switch (align) {
                              case LEFT:
                                  str = ",align=left";
                                  break;
                              case CENTER:
                                  str = ",align=center";
                                  break;
                              case RIGHT:
                                  str = ",align=right";
                                  break;
                              case LEADING:
                                  str = ",align=leading";
                                  break;
                              case TRAILING:
                                  str = ",align=trailing";
                                  break;
                              }
                              return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + str + "]";
                          }
                      
                      }
                      
                      public class WrapLayoutExample {
                          public static void main(String[] args) {
                              SwingUtilities.invokeLater(WrapLayoutExample::runGui);
                          }
                      
                          private static void runGui() {
                              JFrame frame = new JFrame("A");
                              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      
                              JPanel panel = new JPanel(new WrapAndAlignHorizontallyTopLayout());
                      
                              JLabel l = new JLabel("CCC");
                              l.setBorder(BorderFactory.createLineBorder(Color.red, 10));
                              l.setVerticalAlignment(JLabel.TOP);
                      
                              panel.add(l);
                      
                              for (int i = 0; i < 44; i++) {
                                  l = new JLabel("BBBB");
                                  l.setBorder(BorderFactory.createLineBorder(Color.red, (int) (Math.random() * 50)));
                                  panel.add(l);
                              }
                      
                              frame.setSize(300, 300);
                              frame.setLayout(new BorderLayout());
                              frame.add(new JScrollPane(panel));
                              frame.setVisible(true);
                          }
                      }
                      
                      cy = y + (height - m.height) / 2;
                      
                      cy = y;
                      
                      public class WrapAndAlignHorizontallyTopLayout implements LayoutManager, java.io.Serializable {
                      
                          /**
                           * This value indicates that each row of components should be left-justified.
                           */
                          public static final int LEFT = 0;
                      
                          /**
                           * This value indicates that each row of components should be centered.
                           */
                          public static final int CENTER = 1;
                      
                          /**
                           * This value indicates that each row of components should be right-justified.
                           */
                          public static final int RIGHT = 2;
                      
                          /**
                           * This value indicates that each row of components should be justified to the
                           * leading edge of the container's orientation, for example, to the left in
                           * left-to-right orientations.
                           *
                           * @see java.awt.Component#getComponentOrientation
                           * @see java.awt.ComponentOrientation
                           * @since 1.2
                           */
                          public static final int LEADING = 3;
                      
                          /**
                           * This value indicates that each row of components should be justified to the
                           * trailing edge of the container's orientation, for example, to the right in
                           * left-to-right orientations.
                           *
                           * @see java.awt.Component#getComponentOrientation
                           * @see java.awt.ComponentOrientation
                           * @since 1.2
                           */
                          public static final int TRAILING = 4;
                      
                          /**
                           * <code>align</code> is the property that determines how each row distributes
                           * empty space. It can be one of the following values:
                           * <ul>
                           * <li><code>LEFT</code>
                           * <li><code>RIGHT</code>
                           * <li><code>CENTER</code>
                           * </ul>
                           *
                           * @serial
                           * @see #getAlignment
                           * @see #setAlignment
                           */
                          int align; // This is for 1.1 serialization compatibility
                      
                          /**
                           * <code>newAlign</code> is the property that determines how each row
                           * distributes empty space for the Java 2 platform, v1.2 and greater. It can be
                           * one of the following three values:
                           * <ul>
                           * <li><code>LEFT</code>
                           * <li><code>RIGHT</code>
                           * <li><code>CENTER</code>
                           * <li><code>LEADING</code>
                           * <li><code>TRAILING</code>
                           * </ul>
                           *
                           * @serial
                           * @since 1.2
                           * @see #getAlignment
                           * @see #setAlignment
                           */
                          int newAlign; // This is the one we actually use
                      
                          /**
                           * The flow layout manager allows a seperation of components with gaps. The
                           * horizontal gap will specify the space between components and between the
                           * components and the borders of the <code>Container</code>.
                           *
                           * @serial
                           * @see #getHgap()
                           * @see #setHgap(int)
                           */
                          int hgap;
                      
                          /**
                           * The flow layout manager allows a seperation of components with gaps. The
                           * vertical gap will specify the space between rows and between the the rows and
                           * the borders of the <code>Container</code>.
                           *
                           * @serial
                           * @see #getHgap()
                           * @see #setHgap(int)
                           */
                          int vgap;
                      
                          /**
                           * If true, components will be aligned on their baseline.
                           */
                          private boolean alignOnBaseline;
                      
                          /*
                           * JDK 1.1 serialVersionUID
                           */
                          private static final long serialVersionUID = -7262534875583282631L;
                      
                          /**
                           * Constructs a new <code>FlowLayout</code> with a centered alignment and a
                           * default 5-unit horizontal and vertical gap.
                           */
                          public WrapAndAlignHorizontallyTopLayout() {
                              this(CENTER, 5, 5);
                          }
                      
                          /**
                           * Constructs a new <code>FlowLayout</code> with the specified alignment and a
                           * default 5-unit horizontal and vertical gap. The value of the alignment
                           * argument must be one of <code>FlowLayout.LEFT</code>,
                           * <code>FlowLayout.RIGHT</code>, <code>FlowLayout.CENTER</code>,
                           * <code>FlowLayout.LEADING</code>, or <code>FlowLayout.TRAILING</code>.
                           * 
                           * @param align the alignment value
                           */
                          public WrapAndAlignHorizontallyTopLayout(int align) {
                              this(align, 5, 5);
                          }
                      
                          /**
                           * Creates a new flow layout manager with the indicated alignment and the
                           * indicated horizontal and vertical gaps.
                           * <p>
                           * The value of the alignment argument must be one of
                           * <code>FlowLayout.LEFT</code>, <code>FlowLayout.RIGHT</code>,
                           * <code>FlowLayout.CENTER</code>, <code>FlowLayout.LEADING</code>, or
                           * <code>FlowLayout.TRAILING</code>.
                           * 
                           * @param align the alignment value
                           * @param hgap  the horizontal gap between components and between the components
                           *              and the borders of the <code>Container</code>
                           * @param vgap  the vertical gap between components and between the components
                           *              and the borders of the <code>Container</code>
                           */
                          public WrapAndAlignHorizontallyTopLayout(int align, int hgap, int vgap) {
                              this.hgap = hgap;
                              this.vgap = vgap;
                              setAlignment(align);
                          }
                      
                          /**
                           * Gets the alignment for this layout. Possible values are
                           * <code>FlowLayout.LEFT</code>, <code>FlowLayout.RIGHT</code>,
                           * <code>FlowLayout.CENTER</code>, <code>FlowLayout.LEADING</code>, or
                           * <code>FlowLayout.TRAILING</code>.
                           * 
                           * @return the alignment value for this layout
                           * @see java.awt.FlowLayout#setAlignment
                           * @since JDK1.1
                           */
                          public int getAlignment() {
                              return newAlign;
                          }
                      
                          /**
                           * Sets the alignment for this layout. Possible values are
                           * <ul>
                           * <li><code>FlowLayout.LEFT</code>
                           * <li><code>FlowLayout.RIGHT</code>
                           * <li><code>FlowLayout.CENTER</code>
                           * <li><code>FlowLayout.LEADING</code>
                           * <li><code>FlowLayout.TRAILING</code>
                           * </ul>
                           * 
                           * @param align one of the alignment values shown above
                           * @see #getAlignment()
                           * @since JDK1.1
                           */
                          public void setAlignment(int align) {
                              this.newAlign = align;
                      
                              // this.align is used only for serialization compatibility,
                              // so set it to a value compatible with the 1.1 version
                              // of the class
                      
                              switch (align) {
                              case LEADING:
                                  this.align = LEFT;
                                  break;
                              case TRAILING:
                                  this.align = RIGHT;
                                  break;
                              default:
                                  this.align = align;
                                  break;
                              }
                          }
                      
                          /**
                           * Gets the horizontal gap between components and between the components and the
                           * borders of the <code>Container</code>
                           *
                           * @return the horizontal gap between components and between the components and
                           *         the borders of the <code>Container</code>
                           * @see java.awt.FlowLayout#setHgap
                           * @since JDK1.1
                           */
                          public int getHgap() {
                              return hgap;
                          }
                      
                          /**
                           * Sets the horizontal gap between components and between the components and the
                           * borders of the <code>Container</code>.
                           *
                           * @param hgap the horizontal gap between components and between the components
                           *             and the borders of the <code>Container</code>
                           * @see java.awt.FlowLayout#getHgap
                           * @since JDK1.1
                           */
                          public void setHgap(int hgap) {
                              this.hgap = hgap;
                          }
                      
                          /**
                           * Gets the vertical gap between components and between the components and the
                           * borders of the <code>Container</code>.
                           *
                           * @return the vertical gap between components and between the components and
                           *         the borders of the <code>Container</code>
                           * @see java.awt.FlowLayout#setVgap
                           * @since JDK1.1
                           */
                          public int getVgap() {
                              return vgap;
                          }
                      
                          /**
                           * Sets the vertical gap between components and between the components and the
                           * borders of the <code>Container</code>.
                           *
                           * @param vgap the vertical gap between components and between the components
                           *             and the borders of the <code>Container</code>
                           * @see java.awt.FlowLayout#getVgap
                           * @since JDK1.1
                           */
                          public void setVgap(int vgap) {
                              this.vgap = vgap;
                          }
                      
                          /**
                           * Sets whether or not components should be vertically aligned along their
                           * baseline. Components that do not have a baseline will be centered. The
                           * default is false.
                           *
                           * @param alignOnBaseline whether or not components should be vertically aligned
                           *                        on their baseline
                           * @since 1.6
                           */
                          public void setAlignOnBaseline(boolean alignOnBaseline) {
                              this.alignOnBaseline = alignOnBaseline;
                          }
                      
                          /**
                           * Returns true if components are to be vertically aligned along their baseline.
                           * The default is false.
                           *
                           * @return true if components are to be vertically aligned along their baseline
                           * @since 1.6
                           */
                          public boolean getAlignOnBaseline() {
                              return alignOnBaseline;
                          }
                      
                          /**
                           * Adds the specified component to the layout. Not used by this class.
                           * 
                           * @param name the name of the component
                           * @param comp the component to be added
                           */
                          @Override
                          public void addLayoutComponent(String name, Component comp) {
                          }
                      
                          /**
                           * Removes the specified component from the layout. Not used by this class.
                           * 
                           * @param comp the component to remove
                           * @see java.awt.Container#removeAll
                           */
                          @Override
                          public void removeLayoutComponent(Component comp) {
                          }
                      
                          /**
                           * Returns the preferred dimensions for this layout given the <i>visible</i>
                           * components in the specified target container.
                           * 
                           * @param target the component which needs to be laid out
                           * @return the preferred dimensions to lay out the subcomponents of the
                           *         specified container
                           */
                          @Override
                          public Dimension preferredLayoutSize(Container target) {
                              return layoutSize(target, true);
                          }
                      
                          /**
                           * Returns the minimum dimensions needed to layout the <i>visible</i> components
                           * contained in the specified target container.
                           * 
                           * @param target the component which needs to be laid out
                           * @return the minimum dimensions to lay out the subcomponents of the specified
                           *         container
                           */
                          @Override
                          public Dimension minimumLayoutSize(Container target) {
                              Dimension minimum = layoutSize(target, false);
                              minimum.width -= (getHgap() + 1);
                              return minimum;
                          }
                      
                          /**
                           * Returns the minimum or preferred dimension needed to layout the target
                           * container.
                           *
                           * @param target    target to get layout size for
                           * @param preferred should preferred size be calculated
                           * @return the dimension to layout the target container
                           */
                          private Dimension layoutSize(Container target, boolean preferred) {
                              synchronized (target.getTreeLock()) {
                                  // Each row must fit with the width allocated to the containter.
                                  // When the container width = 0, the preferred width of the container
                                  // has not yet been calculated so lets ask for the maximum.
                      
                                  int targetWidth = target.getSize().width;
                                  Container container = target;
                      
                                  while (container.getSize().width == 0 && container.getParent() != null) {
                                      container = container.getParent();
                                  }
                      
                                  targetWidth = container.getSize().width;
                      
                                  if (targetWidth == 0)
                                      targetWidth = Integer.MAX_VALUE;
                      
                                  int hgap = getHgap();
                                  int vgap = getVgap();
                                  Insets insets = target.getInsets();
                                  int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
                                  int maxWidth = targetWidth - horizontalInsetsAndGap;
                      
                                  // Fit components into the allowed width
                      
                                  Dimension dim = new Dimension(0, 0);
                                  int rowWidth = 0;
                                  int rowHeight = 0;
                      
                                  int nmembers = target.getComponentCount();
                      
                                  for (int i = 0; i < nmembers; i++) {
                                      Component m = target.getComponent(i);
                      
                                      if (m.isVisible()) {
                                          Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
                      
                                          // Can't add the component to current row. Start a new row.
                      
                                          if (rowWidth + d.width > maxWidth) {
                                              addRow(dim, rowWidth, rowHeight);
                                              rowWidth = 0;
                                              rowHeight = 0;
                                          }
                      
                                          // Add a horizontal gap for all components after the first
                      
                                          if (rowWidth != 0) {
                                              rowWidth += hgap;
                                          }
                      
                                          rowWidth += d.width;
                                          rowHeight = Math.max(rowHeight, d.height);
                                      }
                                  }
                      
                                  addRow(dim, rowWidth, rowHeight);
                      
                                  dim.width += horizontalInsetsAndGap;
                                  dim.height += insets.top + insets.bottom + vgap * 2;
                      
                                  // When using a scroll pane or the DecoratedLookAndFeel we need to
                                  // make sure the preferred size is less than the size of the
                                  // target containter so shrinking the container size works
                                  // correctly. Removing the horizontal gap is an easy way to do this.
                      
                                  Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
                      
                                  if (scrollPane != null && target.isValid()) {
                                      dim.width -= (hgap + 1);
                                  }
                      
                                  return dim;
                              }
                          }
                      
                          /*
                           * A new row has been completed. Use the dimensions of this row to update the
                           * preferred size for the container.
                           *
                           * @param dim update the width and height when appropriate
                           * 
                           * @param rowWidth the width of the row to add
                           * 
                           * @param rowHeight the height of the row to add
                           */
                          private void addRow(Dimension dim, int rowWidth, int rowHeight) {
                              dim.width = Math.max(dim.width, rowWidth);
                      
                              if (dim.height > 0) {
                                  dim.height += getVgap();
                              }
                      
                              dim.height += rowHeight;
                          }
                      
                          /**
                           * Centers the elements in the specified row, if there is any slack.
                           * 
                           * @param target      the component which needs to be moved
                           * @param x           the x coordinate
                           * @param y           the y coordinate
                           * @param width       the width dimensions
                           * @param height      the height dimensions
                           * @param rowStart    the beginning of the row
                           * @param rowEnd      the the ending of the row
                           * @param useBaseline Whether or not to align on baseline.
                           * @param ascent      Ascent for the components. This is only valid if
                           *                    useBaseline is true.
                           * @param descent     Ascent for the components. This is only valid if
                           *                    useBaseline is true.
                           * @return actual row height
                           */
                          private int moveComponents(Container target, int x, int y, int width, int height, int rowStart, int rowEnd,
                                  boolean ltr, boolean useBaseline, int[] ascent, int[] descent) {
                              switch (newAlign) {
                              case LEFT:
                                  x += ltr ? 0 : width;
                                  break;
                              case CENTER:
                                  x += width / 2;
                                  break;
                              case RIGHT:
                                  x += ltr ? width : 0;
                                  break;
                              case LEADING:
                                  break;
                              case TRAILING:
                                  x += width;
                                  break;
                              }
                              int maxAscent = 0;
                              int nonbaselineHeight = 0;
                              int baselineOffset = 0;
                              if (useBaseline) {
                                  int maxDescent = 0;
                                  for (int i = rowStart; i < rowEnd; i++) {
                                      Component m = target.getComponent(i);
                                      if (m.isVisible()) {
                                          if (ascent[i] >= 0) {
                                              maxAscent = Math.max(maxAscent, ascent[i]);
                                              maxDescent = Math.max(maxDescent, descent[i]);
                                          } else {
                                              nonbaselineHeight = Math.max(m.getHeight(), nonbaselineHeight);
                                          }
                                      }
                                  }
                                  height = Math.max(maxAscent + maxDescent, nonbaselineHeight);
                                  baselineOffset = (height - maxAscent - maxDescent) / 2;
                              }
                              for (int i = rowStart; i < rowEnd; i++) {
                                  Component m = target.getComponent(i);
                                  if (m.isVisible()) {
                                      int cy;
                                      if (useBaseline && ascent[i] >= 0) {
                                          cy = y + baselineOffset + maxAscent - ascent[i];
                                      } else {
                                          cy = y;
                                      }
                                      if (ltr) {
                                          m.setLocation(x, cy);
                                      } else {
                                          m.setLocation(target.getWidth() - x - m.getWidth(), cy);
                                      }
                                      x += m.getWidth() + hgap;
                                  }
                              }
                              return height;
                          }
                      
                          /**
                           * Lays out the container. This method lets each <i>visible</i> component take
                           * its preferred size by reshaping the components in the target container in
                           * order to satisfy the alignment of this <code>FlowLayout</code> object.
                           *
                           * @param target the specified component being laid out
                           * @see Container
                           * @see java.awt.Container#doLayout
                           */
                          @Override
                          public void layoutContainer(Container target) {
                              synchronized (target.getTreeLock()) {
                                  Insets insets = target.getInsets();
                                  int maxwidth = target.getWidth() - (insets.left + insets.right + hgap * 2);
                                  int nmembers = target.getComponentCount();
                                  int x = 0, y = insets.top + vgap;
                                  int rowh = 0, start = 0;
                      
                                  boolean ltr = target.getComponentOrientation().isLeftToRight();
                      
                                  boolean useBaseline = getAlignOnBaseline();
                                  int[] ascent = null;
                                  int[] descent = null;
                      
                                  if (useBaseline) {
                                      ascent = new int[nmembers];
                                      descent = new int[nmembers];
                                  }
                      
                                  for (int i = 0; i < nmembers; i++) {
                                      Component m = target.getComponent(i);
                                      if (m.isVisible()) {
                                          Dimension d = m.getPreferredSize();
                                          m.setSize(d.width, d.height);
                      
                                          if (useBaseline) {
                                              int baseline = m.getBaseline(d.width, d.height);
                                              if (baseline >= 0) {
                                                  ascent[i] = baseline;
                                                  descent[i] = d.height - baseline;
                                              } else {
                                                  ascent[i] = -1;
                                              }
                                          }
                                          if ((x == 0) || ((x + d.width) <= maxwidth)) {
                                              if (x > 0) {
                                                  x += hgap;
                                              }
                                              x += d.width;
                                              rowh = Math.max(rowh, d.height);
                                          } else {
                                              rowh = moveComponents(target, insets.left + hgap, y, maxwidth - x, rowh, start, i, ltr,
                                                      useBaseline, ascent, descent);
                                              x = d.width;
                                              y += vgap + rowh;
                                              rowh = d.height;
                                              start = i;
                                          }
                                      }
                                  }
                                  moveComponents(target, insets.left + hgap, y, maxwidth - x, rowh, start, nmembers, ltr, useBaseline, ascent,
                                          descent);
                              }
                          }
                      
                          //
                          // the internal serial version which says which version was written
                          // - 0 (default) for versions before the Java 2 platform, v1.2
                          // - 1 for version >= Java 2 platform v1.2, which includes "newAlign" field
                          //
                          private static final int currentSerialVersion = 1;
                          /**
                           * This represent the <code>currentSerialVersion</code> which is bein used. It
                           * will be one of two values : <code>0</code> versions before Java 2 platform
                           * v1.2.. <code>1</code> versions after Java 2 platform v1.2..
                           *
                           * @serial
                           * @since 1.2
                           */
                          private int serialVersionOnStream = currentSerialVersion;
                      
                          /**
                           * Reads this object out of a serialization stream, handling objects written by
                           * older versions of the class that didn't contain all of the fields we use
                           * now..
                           */
                          private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
                              stream.defaultReadObject();
                      
                              if (serialVersionOnStream < 1) {
                                  // "newAlign" field wasn't present, so use the old "align" field.
                                  setAlignment(this.align);
                              }
                              serialVersionOnStream = currentSerialVersion;
                          }
                      
                          /**
                           * Returns a string representation of this <code>FlowLayout</code> object and
                           * its values.
                           * 
                           * @return a string representation of this layout
                           */
                          @Override
                          public String toString() {
                              String str = "";
                              switch (align) {
                              case LEFT:
                                  str = ",align=left";
                                  break;
                              case CENTER:
                                  str = ",align=center";
                                  break;
                              case RIGHT:
                                  str = ",align=right";
                                  break;
                              case LEADING:
                                  str = ",align=leading";
                                  break;
                              case TRAILING:
                                  str = ",align=trailing";
                                  break;
                              }
                              return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + str + "]";
                          }
                      
                      }
                      
                      public class WrapLayoutExample {
                          public static void main(String[] args) {
                              SwingUtilities.invokeLater(WrapLayoutExample::runGui);
                          }
                      
                          private static void runGui() {
                              JFrame frame = new JFrame("A");
                              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      
                              JPanel panel = new JPanel(new WrapAndAlignHorizontallyTopLayout());
                      
                              JLabel l = new JLabel("CCC");
                              l.setBorder(BorderFactory.createLineBorder(Color.red, 10));
                              l.setVerticalAlignment(JLabel.TOP);
                      
                              panel.add(l);
                      
                              for (int i = 0; i < 44; i++) {
                                  l = new JLabel("BBBB");
                                  l.setBorder(BorderFactory.createLineBorder(Color.red, (int) (Math.random() * 50)));
                                  panel.add(l);
                              }
                      
                              frame.setSize(300, 300);
                              frame.setLayout(new BorderLayout());
                              frame.add(new JScrollPane(panel));
                              frame.setVisible(true);
                          }
                      }
                      
                      cy = y + (height - m.height) / 2;
                      
                      cy = y;
                      
                      public class WrapAndAlignHorizontallyTopLayout implements LayoutManager, java.io.Serializable {
                      
                          /**
                           * This value indicates that each row of components should be left-justified.
                           */
                          public static final int LEFT = 0;
                      
                          /**
                           * This value indicates that each row of components should be centered.
                           */
                          public static final int CENTER = 1;
                      
                          /**
                           * This value indicates that each row of components should be right-justified.
                           */
                          public static final int RIGHT = 2;
                      
                          /**
                           * This value indicates that each row of components should be justified to the
                           * leading edge of the container's orientation, for example, to the left in
                           * left-to-right orientations.
                           *
                           * @see java.awt.Component#getComponentOrientation
                           * @see java.awt.ComponentOrientation
                           * @since 1.2
                           */
                          public static final int LEADING = 3;
                      
                          /**
                           * This value indicates that each row of components should be justified to the
                           * trailing edge of the container's orientation, for example, to the right in
                           * left-to-right orientations.
                           *
                           * @see java.awt.Component#getComponentOrientation
                           * @see java.awt.ComponentOrientation
                           * @since 1.2
                           */
                          public static final int TRAILING = 4;
                      
                          /**
                           * <code>align</code> is the property that determines how each row distributes
                           * empty space. It can be one of the following values:
                           * <ul>
                           * <li><code>LEFT</code>
                           * <li><code>RIGHT</code>
                           * <li><code>CENTER</code>
                           * </ul>
                           *
                           * @serial
                           * @see #getAlignment
                           * @see #setAlignment
                           */
                          int align; // This is for 1.1 serialization compatibility
                      
                          /**
                           * <code>newAlign</code> is the property that determines how each row
                           * distributes empty space for the Java 2 platform, v1.2 and greater. It can be
                           * one of the following three values:
                           * <ul>
                           * <li><code>LEFT</code>
                           * <li><code>RIGHT</code>
                           * <li><code>CENTER</code>
                           * <li><code>LEADING</code>
                           * <li><code>TRAILING</code>
                           * </ul>
                           *
                           * @serial
                           * @since 1.2
                           * @see #getAlignment
                           * @see #setAlignment
                           */
                          int newAlign; // This is the one we actually use
                      
                          /**
                           * The flow layout manager allows a seperation of components with gaps. The
                           * horizontal gap will specify the space between components and between the
                           * components and the borders of the <code>Container</code>.
                           *
                           * @serial
                           * @see #getHgap()
                           * @see #setHgap(int)
                           */
                          int hgap;
                      
                          /**
                           * The flow layout manager allows a seperation of components with gaps. The
                           * vertical gap will specify the space between rows and between the the rows and
                           * the borders of the <code>Container</code>.
                           *
                           * @serial
                           * @see #getHgap()
                           * @see #setHgap(int)
                           */
                          int vgap;
                      
                          /**
                           * If true, components will be aligned on their baseline.
                           */
                          private boolean alignOnBaseline;
                      
                          /*
                           * JDK 1.1 serialVersionUID
                           */
                          private static final long serialVersionUID = -7262534875583282631L;
                      
                          /**
                           * Constructs a new <code>FlowLayout</code> with a centered alignment and a
                           * default 5-unit horizontal and vertical gap.
                           */
                          public WrapAndAlignHorizontallyTopLayout() {
                              this(CENTER, 5, 5);
                          }
                      
                          /**
                           * Constructs a new <code>FlowLayout</code> with the specified alignment and a
                           * default 5-unit horizontal and vertical gap. The value of the alignment
                           * argument must be one of <code>FlowLayout.LEFT</code>,
                           * <code>FlowLayout.RIGHT</code>, <code>FlowLayout.CENTER</code>,
                           * <code>FlowLayout.LEADING</code>, or <code>FlowLayout.TRAILING</code>.
                           * 
                           * @param align the alignment value
                           */
                          public WrapAndAlignHorizontallyTopLayout(int align) {
                              this(align, 5, 5);
                          }
                      
                          /**
                           * Creates a new flow layout manager with the indicated alignment and the
                           * indicated horizontal and vertical gaps.
                           * <p>
                           * The value of the alignment argument must be one of
                           * <code>FlowLayout.LEFT</code>, <code>FlowLayout.RIGHT</code>,
                           * <code>FlowLayout.CENTER</code>, <code>FlowLayout.LEADING</code>, or
                           * <code>FlowLayout.TRAILING</code>.
                           * 
                           * @param align the alignment value
                           * @param hgap  the horizontal gap between components and between the components
                           *              and the borders of the <code>Container</code>
                           * @param vgap  the vertical gap between components and between the components
                           *              and the borders of the <code>Container</code>
                           */
                          public WrapAndAlignHorizontallyTopLayout(int align, int hgap, int vgap) {
                              this.hgap = hgap;
                              this.vgap = vgap;
                              setAlignment(align);
                          }
                      
                          /**
                           * Gets the alignment for this layout. Possible values are
                           * <code>FlowLayout.LEFT</code>, <code>FlowLayout.RIGHT</code>,
                           * <code>FlowLayout.CENTER</code>, <code>FlowLayout.LEADING</code>, or
                           * <code>FlowLayout.TRAILING</code>.
                           * 
                           * @return the alignment value for this layout
                           * @see java.awt.FlowLayout#setAlignment
                           * @since JDK1.1
                           */
                          public int getAlignment() {
                              return newAlign;
                          }
                      
                          /**
                           * Sets the alignment for this layout. Possible values are
                           * <ul>
                           * <li><code>FlowLayout.LEFT</code>
                           * <li><code>FlowLayout.RIGHT</code>
                           * <li><code>FlowLayout.CENTER</code>
                           * <li><code>FlowLayout.LEADING</code>
                           * <li><code>FlowLayout.TRAILING</code>
                           * </ul>
                           * 
                           * @param align one of the alignment values shown above
                           * @see #getAlignment()
                           * @since JDK1.1
                           */
                          public void setAlignment(int align) {
                              this.newAlign = align;
                      
                              // this.align is used only for serialization compatibility,
                              // so set it to a value compatible with the 1.1 version
                              // of the class
                      
                              switch (align) {
                              case LEADING:
                                  this.align = LEFT;
                                  break;
                              case TRAILING:
                                  this.align = RIGHT;
                                  break;
                              default:
                                  this.align = align;
                                  break;
                              }
                          }
                      
                          /**
                           * Gets the horizontal gap between components and between the components and the
                           * borders of the <code>Container</code>
                           *
                           * @return the horizontal gap between components and between the components and
                           *         the borders of the <code>Container</code>
                           * @see java.awt.FlowLayout#setHgap
                           * @since JDK1.1
                           */
                          public int getHgap() {
                              return hgap;
                          }
                      
                          /**
                           * Sets the horizontal gap between components and between the components and the
                           * borders of the <code>Container</code>.
                           *
                           * @param hgap the horizontal gap between components and between the components
                           *             and the borders of the <code>Container</code>
                           * @see java.awt.FlowLayout#getHgap
                           * @since JDK1.1
                           */
                          public void setHgap(int hgap) {
                              this.hgap = hgap;
                          }
                      
                          /**
                           * Gets the vertical gap between components and between the components and the
                           * borders of the <code>Container</code>.
                           *
                           * @return the vertical gap between components and between the components and
                           *         the borders of the <code>Container</code>
                           * @see java.awt.FlowLayout#setVgap
                           * @since JDK1.1
                           */
                          public int getVgap() {
                              return vgap;
                          }
                      
                          /**
                           * Sets the vertical gap between components and between the components and the
                           * borders of the <code>Container</code>.
                           *
                           * @param vgap the vertical gap between components and between the components
                           *             and the borders of the <code>Container</code>
                           * @see java.awt.FlowLayout#getVgap
                           * @since JDK1.1
                           */
                          public void setVgap(int vgap) {
                              this.vgap = vgap;
                          }
                      
                          /**
                           * Sets whether or not components should be vertically aligned along their
                           * baseline. Components that do not have a baseline will be centered. The
                           * default is false.
                           *
                           * @param alignOnBaseline whether or not components should be vertically aligned
                           *                        on their baseline
                           * @since 1.6
                           */
                          public void setAlignOnBaseline(boolean alignOnBaseline) {
                              this.alignOnBaseline = alignOnBaseline;
                          }
                      
                          /**
                           * Returns true if components are to be vertically aligned along their baseline.
                           * The default is false.
                           *
                           * @return true if components are to be vertically aligned along their baseline
                           * @since 1.6
                           */
                          public boolean getAlignOnBaseline() {
                              return alignOnBaseline;
                          }
                      
                          /**
                           * Adds the specified component to the layout. Not used by this class.
                           * 
                           * @param name the name of the component
                           * @param comp the component to be added
                           */
                          @Override
                          public void addLayoutComponent(String name, Component comp) {
                          }
                      
                          /**
                           * Removes the specified component from the layout. Not used by this class.
                           * 
                           * @param comp the component to remove
                           * @see java.awt.Container#removeAll
                           */
                          @Override
                          public void removeLayoutComponent(Component comp) {
                          }
                      
                          /**
                           * Returns the preferred dimensions for this layout given the <i>visible</i>
                           * components in the specified target container.
                           * 
                           * @param target the component which needs to be laid out
                           * @return the preferred dimensions to lay out the subcomponents of the
                           *         specified container
                           */
                          @Override
                          public Dimension preferredLayoutSize(Container target) {
                              return layoutSize(target, true);
                          }
                      
                          /**
                           * Returns the minimum dimensions needed to layout the <i>visible</i> components
                           * contained in the specified target container.
                           * 
                           * @param target the component which needs to be laid out
                           * @return the minimum dimensions to lay out the subcomponents of the specified
                           *         container
                           */
                          @Override
                          public Dimension minimumLayoutSize(Container target) {
                              Dimension minimum = layoutSize(target, false);
                              minimum.width -= (getHgap() + 1);
                              return minimum;
                          }
                      
                          /**
                           * Returns the minimum or preferred dimension needed to layout the target
                           * container.
                           *
                           * @param target    target to get layout size for
                           * @param preferred should preferred size be calculated
                           * @return the dimension to layout the target container
                           */
                          private Dimension layoutSize(Container target, boolean preferred) {
                              synchronized (target.getTreeLock()) {
                                  // Each row must fit with the width allocated to the containter.
                                  // When the container width = 0, the preferred width of the container
                                  // has not yet been calculated so lets ask for the maximum.
                      
                                  int targetWidth = target.getSize().width;
                                  Container container = target;
                      
                                  while (container.getSize().width == 0 && container.getParent() != null) {
                                      container = container.getParent();
                                  }
                      
                                  targetWidth = container.getSize().width;
                      
                                  if (targetWidth == 0)
                                      targetWidth = Integer.MAX_VALUE;
                      
                                  int hgap = getHgap();
                                  int vgap = getVgap();
                                  Insets insets = target.getInsets();
                                  int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
                                  int maxWidth = targetWidth - horizontalInsetsAndGap;
                      
                                  // Fit components into the allowed width
                      
                                  Dimension dim = new Dimension(0, 0);
                                  int rowWidth = 0;
                                  int rowHeight = 0;
                      
                                  int nmembers = target.getComponentCount();
                      
                                  for (int i = 0; i < nmembers; i++) {
                                      Component m = target.getComponent(i);
                      
                                      if (m.isVisible()) {
                                          Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
                      
                                          // Can't add the component to current row. Start a new row.
                      
                                          if (rowWidth + d.width > maxWidth) {
                                              addRow(dim, rowWidth, rowHeight);
                                              rowWidth = 0;
                                              rowHeight = 0;
                                          }
                      
                                          // Add a horizontal gap for all components after the first
                      
                                          if (rowWidth != 0) {
                                              rowWidth += hgap;
                                          }
                      
                                          rowWidth += d.width;
                                          rowHeight = Math.max(rowHeight, d.height);
                                      }
                                  }
                      
                                  addRow(dim, rowWidth, rowHeight);
                      
                                  dim.width += horizontalInsetsAndGap;
                                  dim.height += insets.top + insets.bottom + vgap * 2;
                      
                                  // When using a scroll pane or the DecoratedLookAndFeel we need to
                                  // make sure the preferred size is less than the size of the
                                  // target containter so shrinking the container size works
                                  // correctly. Removing the horizontal gap is an easy way to do this.
                      
                                  Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
                      
                                  if (scrollPane != null && target.isValid()) {
                                      dim.width -= (hgap + 1);
                                  }
                      
                                  return dim;
                              }
                          }
                      
                          /*
                           * A new row has been completed. Use the dimensions of this row to update the
                           * preferred size for the container.
                           *
                           * @param dim update the width and height when appropriate
                           * 
                           * @param rowWidth the width of the row to add
                           * 
                           * @param rowHeight the height of the row to add
                           */
                          private void addRow(Dimension dim, int rowWidth, int rowHeight) {
                              dim.width = Math.max(dim.width, rowWidth);
                      
                              if (dim.height > 0) {
                                  dim.height += getVgap();
                              }
                      
                              dim.height += rowHeight;
                          }
                      
                          /**
                           * Centers the elements in the specified row, if there is any slack.
                           * 
                           * @param target      the component which needs to be moved
                           * @param x           the x coordinate
                           * @param y           the y coordinate
                           * @param width       the width dimensions
                           * @param height      the height dimensions
                           * @param rowStart    the beginning of the row
                           * @param rowEnd      the the ending of the row
                           * @param useBaseline Whether or not to align on baseline.
                           * @param ascent      Ascent for the components. This is only valid if
                           *                    useBaseline is true.
                           * @param descent     Ascent for the components. This is only valid if
                           *                    useBaseline is true.
                           * @return actual row height
                           */
                          private int moveComponents(Container target, int x, int y, int width, int height, int rowStart, int rowEnd,
                                  boolean ltr, boolean useBaseline, int[] ascent, int[] descent) {
                              switch (newAlign) {
                              case LEFT:
                                  x += ltr ? 0 : width;
                                  break;
                              case CENTER:
                                  x += width / 2;
                                  break;
                              case RIGHT:
                                  x += ltr ? width : 0;
                                  break;
                              case LEADING:
                                  break;
                              case TRAILING:
                                  x += width;
                                  break;
                              }
                              int maxAscent = 0;
                              int nonbaselineHeight = 0;
                              int baselineOffset = 0;
                              if (useBaseline) {
                                  int maxDescent = 0;
                                  for (int i = rowStart; i < rowEnd; i++) {
                                      Component m = target.getComponent(i);
                                      if (m.isVisible()) {
                                          if (ascent[i] >= 0) {
                                              maxAscent = Math.max(maxAscent, ascent[i]);
                                              maxDescent = Math.max(maxDescent, descent[i]);
                                          } else {
                                              nonbaselineHeight = Math.max(m.getHeight(), nonbaselineHeight);
                                          }
                                      }
                                  }
                                  height = Math.max(maxAscent + maxDescent, nonbaselineHeight);
                                  baselineOffset = (height - maxAscent - maxDescent) / 2;
                              }
                              for (int i = rowStart; i < rowEnd; i++) {
                                  Component m = target.getComponent(i);
                                  if (m.isVisible()) {
                                      int cy;
                                      if (useBaseline && ascent[i] >= 0) {
                                          cy = y + baselineOffset + maxAscent - ascent[i];
                                      } else {
                                          cy = y;
                                      }
                                      if (ltr) {
                                          m.setLocation(x, cy);
                                      } else {
                                          m.setLocation(target.getWidth() - x - m.getWidth(), cy);
                                      }
                                      x += m.getWidth() + hgap;
                                  }
                              }
                              return height;
                          }
                      
                          /**
                           * Lays out the container. This method lets each <i>visible</i> component take
                           * its preferred size by reshaping the components in the target container in
                           * order to satisfy the alignment of this <code>FlowLayout</code> object.
                           *
                           * @param target the specified component being laid out
                           * @see Container
                           * @see java.awt.Container#doLayout
                           */
                          @Override
                          public void layoutContainer(Container target) {
                              synchronized (target.getTreeLock()) {
                                  Insets insets = target.getInsets();
                                  int maxwidth = target.getWidth() - (insets.left + insets.right + hgap * 2);
                                  int nmembers = target.getComponentCount();
                                  int x = 0, y = insets.top + vgap;
                                  int rowh = 0, start = 0;
                      
                                  boolean ltr = target.getComponentOrientation().isLeftToRight();
                      
                                  boolean useBaseline = getAlignOnBaseline();
                                  int[] ascent = null;
                                  int[] descent = null;
                      
                                  if (useBaseline) {
                                      ascent = new int[nmembers];
                                      descent = new int[nmembers];
                                  }
                      
                                  for (int i = 0; i < nmembers; i++) {
                                      Component m = target.getComponent(i);
                                      if (m.isVisible()) {
                                          Dimension d = m.getPreferredSize();
                                          m.setSize(d.width, d.height);
                      
                                          if (useBaseline) {
                                              int baseline = m.getBaseline(d.width, d.height);
                                              if (baseline >= 0) {
                                                  ascent[i] = baseline;
                                                  descent[i] = d.height - baseline;
                                              } else {
                                                  ascent[i] = -1;
                                              }
                                          }
                                          if ((x == 0) || ((x + d.width) <= maxwidth)) {
                                              if (x > 0) {
                                                  x += hgap;
                                              }
                                              x += d.width;
                                              rowh = Math.max(rowh, d.height);
                                          } else {
                                              rowh = moveComponents(target, insets.left + hgap, y, maxwidth - x, rowh, start, i, ltr,
                                                      useBaseline, ascent, descent);
                                              x = d.width;
                                              y += vgap + rowh;
                                              rowh = d.height;
                                              start = i;
                                          }
                                      }
                                  }
                                  moveComponents(target, insets.left + hgap, y, maxwidth - x, rowh, start, nmembers, ltr, useBaseline, ascent,
                                          descent);
                              }
                          }
                      
                          //
                          // the internal serial version which says which version was written
                          // - 0 (default) for versions before the Java 2 platform, v1.2
                          // - 1 for version >= Java 2 platform v1.2, which includes "newAlign" field
                          //
                          private static final int currentSerialVersion = 1;
                          /**
                           * This represent the <code>currentSerialVersion</code> which is bein used. It
                           * will be one of two values : <code>0</code> versions before Java 2 platform
                           * v1.2.. <code>1</code> versions after Java 2 platform v1.2..
                           *
                           * @serial
                           * @since 1.2
                           */
                          private int serialVersionOnStream = currentSerialVersion;
                      
                          /**
                           * Reads this object out of a serialization stream, handling objects written by
                           * older versions of the class that didn't contain all of the fields we use
                           * now..
                           */
                          private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
                              stream.defaultReadObject();
                      
                              if (serialVersionOnStream < 1) {
                                  // "newAlign" field wasn't present, so use the old "align" field.
                                  setAlignment(this.align);
                              }
                              serialVersionOnStream = currentSerialVersion;
                          }
                      
                          /**
                           * Returns a string representation of this <code>FlowLayout</code> object and
                           * its values.
                           * 
                           * @return a string representation of this layout
                           */
                          @Override
                          public String toString() {
                              String str = "";
                              switch (align) {
                              case LEFT:
                                  str = ",align=left";
                                  break;
                              case CENTER:
                                  str = ",align=center";
                                  break;
                              case RIGHT:
                                  str = ",align=right";
                                  break;
                              case LEADING:
                                  str = ",align=leading";
                                  break;
                              case TRAILING:
                                  str = ",align=trailing";
                                  break;
                              }
                              return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + str + "]";
                          }
                      
                      }
                      
                      public class WrapLayoutExample {
                          public static void main(String[] args) {
                              SwingUtilities.invokeLater(WrapLayoutExample::runGui);
                          }
                      
                          private static void runGui() {
                              JFrame frame = new JFrame("A");
                              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      
                              JPanel panel = new JPanel(new WrapAndAlignHorizontallyTopLayout());
                      
                              JLabel l = new JLabel("CCC");
                              l.setBorder(BorderFactory.createLineBorder(Color.red, 10));
                              l.setVerticalAlignment(JLabel.TOP);
                      
                              panel.add(l);
                      
                              for (int i = 0; i < 44; i++) {
                                  l = new JLabel("BBBB");
                                  l.setBorder(BorderFactory.createLineBorder(Color.red, (int) (Math.random() * 50)));
                                  panel.add(l);
                              }
                      
                              frame.setSize(300, 300);
                              frame.setLayout(new BorderLayout());
                              frame.add(new JScrollPane(panel));
                              frame.setVisible(true);
                          }
                      }
                      

                      Prevent WordPress' default input sanitization

                      copy iconCopydownload iconDownload
                      /*
                      * Filters the output from sanitize_text_field
                      * @param $filtered string - the sanitized string
                      * @param $original_string string - the original unsanitized string
                      *
                      * @return string - the unsanitized string
                      */
                      add_filter( 'sanitize_text_field', static function( $filtered, $original_string ) { return $original_string; }, 10, 2 ); 
                      
                      $_SPOST = null;
                      if (isset($_SERVER['REQUEST_METHOD']) && strtoupper($_SERVER['REQUEST_METHOD']) === 'POST') {
                         $_SPOST = $_POST;
                      }
                      
                      <?php
                          //PHP code for action.php file
                          echo $_SPOST['mycode'];//This output will have all the special characters escaped
                          //I need this to give me the original text entered by the user without /s. 
                      ?>
                      
                      function use_spost() {
                        if (isset($_SPOST)) $_POST = $_SPOST;
                      }
                      add_action('parse_request', 'use_spost', 1);
                      
                      $_SPOST = null;
                      if (isset($_SERVER['REQUEST_METHOD']) && strtoupper($_SERVER['REQUEST_METHOD']) === 'POST') {
                         $_SPOST = $_POST;
                      }
                      
                      <?php
                          //PHP code for action.php file
                          echo $_SPOST['mycode'];//This output will have all the special characters escaped
                          //I need this to give me the original text entered by the user without /s. 
                      ?>
                      
                      function use_spost() {
                        if (isset($_SPOST)) $_POST = $_SPOST;
                      }
                      add_action('parse_request', 'use_spost', 1);
                      
                      $_SPOST = null;
                      if (isset($_SERVER['REQUEST_METHOD']) && strtoupper($_SERVER['REQUEST_METHOD']) === 'POST') {
                         $_SPOST = $_POST;
                      }
                      
                      <?php
                          //PHP code for action.php file
                          echo $_SPOST['mycode'];//This output will have all the special characters escaped
                          //I need this to give me the original text entered by the user without /s. 
                      ?>
                      
                      function use_spost() {
                        if (isset($_SPOST)) $_POST = $_SPOST;
                      }
                      add_action('parse_request', 'use_spost', 1);
                      

                      Community Discussions

                      Trending Discussions on WordPress
                      • Is it possible to add settings to &quot;allow-plugins&quot; in config section in composer.json through the CLI?
                      • Failed to load next.config.js
                      • EXPORTHOW and DECLARE - what are they?
                      • clarity.js by Microsoft slowing overall page loads
                      • vvv.test not loading (nor any of my sites) when running vagrant up
                      • How to get the image links from Gutenberg block gallery and add them as html data attributes to a button in wordpress
                      • Using EXPORTHOW to make declarator that acts like &quot;sub&quot;
                      • jQuery: How to set max height of 3 'h3' element under a specific DIV to all h3 element?
                      • Woocommerce admin_notices does not work when woocommerce_order_status_changed hook fires
                      • Wordpress site hacked -- redirects to another site
                      Trending Discussions on WordPress

                      QUESTION

                      Is it possible to add settings to &quot;allow-plugins&quot; in config section in composer.json through the CLI?

                      Asked 2022-Mar-29 at 08:31

                      Since composer 2.2 the setting allow-plugins will be compulsory I’ve tried to push this setting through the composer config command in the CLI but with no luck.

                      I’ve tried a few commands like:

                      • composer config --json '{"allow-plugins.composer/installers":true, "allow-plugins.dealerdirect/phpcodesniffer-composer-installer": true, "allow-plugins.roots/wordpress-core-installer": true }'

                      • composer config config.allow-plugins '{"composer/installers":true, "dealerdirect/phpcodesniffer-composer-installer": true, "wordpress-core-installer": true}'

                      • composer config --append "allow-plugins" "composer/installers":true, "dealerdirect/phpcodesniffer-composer-installer": true, "wordpress-core-installer": true

                      • composer config --json "allow-plugins" '{"composer/installers":true, "dealerdirect/phpcodesniffer-composer-installer": true, "roots/wordpress-core-installer": true }'

                      All I get is error messages like ".. is not defined" or that it is an invalid value.

                      What I have is this:

                      ​ "config": {
                              "optimize-autoloader": true,
                              "preferred-install": "dist"
                      },​​​​​​
                      

                      And, I need to add the settings like this:

                      ​​​"config": {
                          "optimize-autoloader": true,
                          "preferred-install": "dist",
                          "allow-plugins": {
                              "composer/installers": true,
                              "dealerdirect/phpcodesniffer-composer-installer": true,
                              "roots/wordpress-core-installer": true
                           }
                      },​​​​​
                      

                      Is this possible through the CLI?

                      ANSWER

                      Answered 2022-Mar-29 at 08:31

                      You need to pass set them one by one.

                      composer config allow-plugins.composer/installers true
                      composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer  true
                      composer config allow-plugins.roots/wordpress-core-installer true
                      

                      Edit per conversation in comments:

                      OP was looking to also achieve not being prompted during the command. To do this, we must pass the --no-interaction (or -n) option. This can be useful when performing automation tasks.

                      Full Example of OP's Plugins:

                      composer config --no-interaction allow-plugins.composer/installerstrue
                      composer config --no-interaction allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
                      composer config --no-interaction allow-plugins.roots/wordpress-core-installer true
                      

                      Source https://stackoverflow.com/questions/70580831

                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                      Vulnerabilities

                      No vulnerabilities reported

                      Install WordPress

                      You can download it from GitHub.
                      PHP requires the Visual C runtime (CRT). The Microsoft Visual C++ Redistributable for Visual Studio 2019 is suitable for all these PHP versions, see visualstudio.microsoft.com. You MUST download the x86 CRT for PHP x86 builds and the x64 CRT for PHP x64 builds. The CRT installer supports the /quiet and /norestart command-line switches, so you can also script it.

                      Support

                      For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

                      DOWNLOAD this Library from

                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      Share this Page

                      share link
                      Consider Popular Content Management System Libraries
                      Try Top Libraries by WordPress
                      Compare Content Management System Libraries with Highest Support
                      Compare Content Management System Libraries with Highest Quality
                      Compare Content Management System Libraries with Highest Security
                      Compare Content Management System Libraries with Permissive License
                      Compare Content Management System Libraries with Highest Reuse
                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      • © 2022 Open Weaver Inc.