< prev index next >

src/java.desktop/share/classes/javax/swing/BorderFactory.java

Print this page




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javax.swing;
  26 
  27 import java.awt.BasicStroke;
  28 import java.awt.Color;
  29 import java.awt.Font;
  30 import java.awt.Paint;
  31 import javax.swing.border.*;
  32 
  33 /**
  34  * Factory class for vending standard <code>Border</code> objects.  Wherever
  35  * possible, this factory will hand out references to shared
  36  * <code>Border</code> instances.
  37  * For further information and examples see
  38  * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/border.html">How
  39  to Use Borders</a>,
  40  * a section in <em>The Java Tutorial</em>.
  41  *
  42  * @author David Kloba
  43  * @since 1.2
  44  */
  45 public class BorderFactory
  46 {
  47 
  48     /** Don't let anyone instantiate this class */
  49     private BorderFactory() {
  50     }
  51 
  52 
  53 //// LineBorder ///////////////////////////////////////////////////////////////
  54     /**
  55      * Creates a line border withe the specified color.
  56      *
  57      * @param color  a <code>Color</code> to use for the line
  58      * @return the <code>Border</code> object
  59      */
  60     public static Border createLineBorder(Color color) {
  61         return new LineBorder(color, 1);
  62     }
  63 
  64     /**
  65      * Creates a line border with the specified color
  66      * and width. The width applies to all four sides of the
  67      * border. To specify widths individually for the top,
  68      * bottom, left, and right, use
  69      * {@link #createMatteBorder(int,int,int,int,Color)}.
  70      *
  71      * @param color  a <code>Color</code> to use for the line
  72      * @param thickness  an integer specifying the width in pixels
  73      * @return the <code>Border</code> object
  74      */
  75     public static Border createLineBorder(Color color, int thickness)  {
  76         return new LineBorder(color, thickness);
  77     }
  78 
  79     /**
  80      * Creates a line border with the specified color, thickness, and corner shape.
  81      *
  82      * @param color      the color of the border
  83      * @param thickness  the thickness of the border
  84      * @param rounded    whether or not border corners should be round
  85      * @return the {@code Border} object
  86      *
  87      * @see LineBorder#LineBorder(Color, int, boolean)
  88      * @since 1.7
  89      */
  90     public static Border createLineBorder(Color color, int thickness, boolean rounded) {
  91         return new LineBorder(color, thickness, rounded);
  92     }
  93 
  94 //// BevelBorder /////////////////////////////////////////////////////////////
  95 ///////////////////////////////////////////////////////////////////////////////
  96     static final Border sharedRaisedBevel = new BevelBorder(BevelBorder.RAISED);
  97     static final Border sharedLoweredBevel = new BevelBorder(BevelBorder.LOWERED);
  98 
  99     /**
 100      * Creates a border with a raised beveled edge, using
 101      * brighter shades of the component's current background color
 102      * for highlighting, and darker shading for shadows.
 103      * (In a raised border, highlights are on top and shadows
 104      *  are underneath.)
 105      *
 106      * @return the <code>Border</code> object
 107      */
 108     public static Border createRaisedBevelBorder() {
 109         return createSharedBevel(BevelBorder.RAISED);
 110     }
 111 
 112     /**
 113      * Creates a border with a lowered beveled edge, using
 114      * brighter shades of the component's current background color
 115      * for highlighting, and darker shading for shadows.
 116      * (In a lowered border, shadows are on top and highlights
 117      *  are underneath.)
 118      *
 119      * @return the <code>Border</code> object
 120      */
 121     public static Border createLoweredBevelBorder() {
 122         return createSharedBevel(BevelBorder.LOWERED);
 123     }
 124 
 125     /**
 126      * Creates a beveled border of the specified type, using
 127      * brighter shades of the component's current background color
 128      * for highlighting, and darker shading for shadows.
 129      * (In a lowered border, shadows are on top and highlights
 130      *  are underneath.)
 131      *
 132      * @param type  an integer specifying either
 133      *                  <code>BevelBorder.LOWERED</code> or
 134      *                  <code>BevelBorder.RAISED</code>
 135      * @return the <code>Border</code> object
 136      */
 137     public static Border createBevelBorder(int type) {
 138         return createSharedBevel(type);
 139     }
 140 
 141     /**
 142      * Creates a beveled border of the specified type, using
 143      * the specified highlighting and shadowing. The outer
 144      * edge of the highlighted area uses a brighter shade of
 145      * the highlight color. The inner edge of the shadow area
 146      * uses a brighter shade of the shadow color.
 147      *
 148      * @param type  an integer specifying either
 149      *                  <code>BevelBorder.LOWERED</code> or
 150      *                  <code>BevelBorder.RAISED</code>
 151      * @param highlight  a <code>Color</code> object for highlights
 152      * @param shadow     a <code>Color</code> object for shadows
 153      * @return the <code>Border</code> object
 154      */
 155     public static Border createBevelBorder(int type, Color highlight, Color shadow) {
 156         return new BevelBorder(type, highlight, shadow);
 157     }
 158 
 159     /**
 160      * Creates a beveled border of the specified type, using
 161      * the specified colors for the inner and outer highlight
 162      * and shadow areas.
 163      *
 164      * @param type  an integer specifying either
 165      *          <code>BevelBorder.LOWERED</code> or
 166      *          <code>BevelBorder.RAISED</code>
 167      * @param highlightOuter  a <code>Color</code> object for the
 168      *                  outer edge of the highlight area
 169      * @param highlightInner  a <code>Color</code> object for the
 170      *                  inner edge of the highlight area
 171      * @param shadowOuter     a <code>Color</code> object for the
 172      *                  outer edge of the shadow area
 173      * @param shadowInner     a <code>Color</code> object for the
 174      *                  inner edge of the shadow area
 175      * @return the <code>Border</code> object
 176      */
 177     public static Border createBevelBorder(int type,
 178                         Color highlightOuter, Color highlightInner,
 179                         Color shadowOuter, Color shadowInner) {
 180         return new BevelBorder(type, highlightOuter, highlightInner,
 181                                         shadowOuter, shadowInner);
 182     }
 183 
 184     static Border createSharedBevel(int type)   {
 185         if(type == BevelBorder.RAISED) {
 186             return sharedRaisedBevel;
 187         } else if(type == BevelBorder.LOWERED) {
 188             return sharedLoweredBevel;
 189         }
 190         return null;
 191     }
 192 
 193 //// SoftBevelBorder ///////////////////////////////////////////////////////////
 194 ////////////////////////////////////////////////////////////////////////////////
 195 


 289      * @param shadowInner     a color of the inner edge of the shadow area
 290      * @return the {@code Border} object
 291      *
 292      * @see BevelBorder#BevelBorder(int, Color, Color, Color, Color)
 293      * @since 1.7
 294      */
 295     public static Border createSoftBevelBorder(int type, Color highlightOuter, Color highlightInner, Color shadowOuter, Color shadowInner) {
 296         return new SoftBevelBorder(type, highlightOuter, highlightInner, shadowOuter, shadowInner);
 297     }
 298 
 299 //// EtchedBorder ///////////////////////////////////////////////////////////
 300 
 301     static final Border sharedEtchedBorder = new EtchedBorder();
 302     private static Border sharedRaisedEtchedBorder;
 303 
 304     /**
 305      * Creates a border with an "etched" look using
 306      * the component's current background color for
 307      * highlighting and shading.
 308      *
 309      * @return the <code>Border</code> object
 310      */
 311     public static Border createEtchedBorder()    {
 312         return sharedEtchedBorder;
 313     }
 314 
 315     /**
 316      * Creates a border with an "etched" look using
 317      * the specified highlighting and shading colors.
 318      *
 319      * @param highlight  a <code>Color</code> object for the border highlights
 320      * @param shadow     a <code>Color</code> object for the border shadows
 321      * @return the <code>Border</code> object
 322      */
 323     public static Border createEtchedBorder(Color highlight, Color shadow)    {
 324         return new EtchedBorder(highlight, shadow);
 325     }
 326 
 327     /**
 328      * Creates a border with an "etched" look using
 329      * the component's current background color for
 330      * highlighting and shading.
 331      *
 332      * @param type      one of <code>EtchedBorder.RAISED</code>, or
 333      *                  <code>EtchedBorder.LOWERED</code>
 334      * @return the <code>Border</code> object
 335      * @exception IllegalArgumentException if type is not either
 336      *                  <code>EtchedBorder.RAISED</code> or
 337      *                  <code>EtchedBorder.LOWERED</code>
 338      * @since 1.3
 339      */
 340     public static Border createEtchedBorder(int type)    {
 341         switch (type) {
 342         case EtchedBorder.RAISED:
 343             if (sharedRaisedEtchedBorder == null) {
 344                 sharedRaisedEtchedBorder = new EtchedBorder
 345                                            (EtchedBorder.RAISED);
 346             }
 347             return sharedRaisedEtchedBorder;
 348         case EtchedBorder.LOWERED:
 349             return sharedEtchedBorder;
 350         default:
 351             throw new IllegalArgumentException("type must be one of EtchedBorder.RAISED or EtchedBorder.LOWERED");
 352         }
 353     }
 354 
 355     /**
 356      * Creates a border with an "etched" look using
 357      * the specified highlighting and shading colors.
 358      *
 359      * @param type      one of <code>EtchedBorder.RAISED</code>, or
 360      *                  <code>EtchedBorder.LOWERED</code>
 361      * @param highlight  a <code>Color</code> object for the border highlights
 362      * @param shadow     a <code>Color</code> object for the border shadows
 363      * @return the <code>Border</code> object
 364      * @since 1.3
 365      */
 366     public static Border createEtchedBorder(int type, Color highlight,
 367                                             Color shadow)    {
 368         return new EtchedBorder(type, highlight, shadow);
 369     }
 370 
 371 //// TitledBorder ////////////////////////////////////////////////////////////
 372     /**
 373      * Creates a new titled border with the specified title,
 374      * the default border type (determined by the current look and feel),
 375      * the default text position (determined by the current look and feel),
 376      * the default justification (leading), and the default
 377      * font and text color (determined by the current look and feel).
 378      *
 379      * @param title      a <code>String</code> containing the text of the title
 380      * @return the <code>TitledBorder</code> object
 381      */
 382     public static TitledBorder createTitledBorder(String title)     {
 383         return new TitledBorder(title);
 384     }
 385 
 386     /**
 387      * Creates a new titled border with an empty title,
 388      * the specified border object,
 389      * the default text position (determined by the current look and feel),
 390      * the default justification (leading), and the default
 391      * font and text color (determined by the current look and feel).
 392      *
 393      * @param border     the <code>Border</code> object to add the title to; if
 394      *                   <code>null</code> the <code>Border</code> is determined
 395      *                   by the current look and feel.
 396      * @return the <code>TitledBorder</code> object
 397      */
 398     public static TitledBorder createTitledBorder(Border border)       {
 399         return new TitledBorder(border);
 400     }
 401 
 402     /**
 403      * Adds a title to an existing border,
 404      * with default positioning (determined by the current look and feel),
 405      * default justification (leading) and the default
 406      * font and text color (determined by the current look and feel).
 407      *
 408      * @param border     the <code>Border</code> object to add the title to
 409      * @param title      a <code>String</code> containing the text of the title
 410      * @return the <code>TitledBorder</code> object
 411      */
 412     public static TitledBorder createTitledBorder(Border border,
 413                                                    String title) {
 414         return new TitledBorder(border, title);
 415     }
 416 
 417     /**
 418      * Adds a title to an existing border, with the specified
 419      * positioning and using the default
 420      * font and text color (determined by the current look and feel).
 421      *
 422      * @param border      the <code>Border</code> object to add the title to
 423      * @param title       a <code>String</code> containing the text of the title
 424      * @param titleJustification  an integer specifying the justification
 425      *        of the title -- one of the following:
 426      *<ul>
 427      *<li><code>TitledBorder.LEFT</code>
 428      *<li><code>TitledBorder.CENTER</code>
 429      *<li><code>TitledBorder.RIGHT</code>
 430      *<li><code>TitledBorder.LEADING</code>
 431      *<li><code>TitledBorder.TRAILING</code>
 432      *<li><code>TitledBorder.DEFAULT_JUSTIFICATION</code> (leading)
 433      *</ul>
 434      * @param titlePosition       an integer specifying the vertical position of
 435      *        the text in relation to the border -- one of the following:
 436      *<ul>
 437      *<li><code> TitledBorder.ABOVE_TOP</code>
 438      *<li><code>TitledBorder.TOP</code> (sitting on the top line)
 439      *<li><code>TitledBorder.BELOW_TOP</code>
 440      *<li><code>TitledBorder.ABOVE_BOTTOM</code>
 441      *<li><code>TitledBorder.BOTTOM</code> (sitting on the bottom line)
 442      *<li><code>TitledBorder.BELOW_BOTTOM</code>
 443      *<li><code>TitledBorder.DEFAULT_POSITION</code> (the title position
 444      *  is determined by the current look and feel)
 445      *</ul>
 446      * @return the <code>TitledBorder</code> object
 447      */
 448     public static TitledBorder createTitledBorder(Border border,
 449                         String title,
 450                         int titleJustification,
 451                         int titlePosition)      {
 452         return new TitledBorder(border, title, titleJustification,
 453                         titlePosition);
 454     }
 455 
 456     /**
 457      * Adds a title to an existing border, with the specified
 458      * positioning and font, and using the default text color
 459      * (determined by the current look and feel).
 460      *
 461      * @param border      the <code>Border</code> object to add the title to
 462      * @param title       a <code>String</code> containing the text of the title
 463      * @param titleJustification  an integer specifying the justification
 464      *        of the title -- one of the following:
 465      *<ul>
 466      *<li><code>TitledBorder.LEFT</code>
 467      *<li><code>TitledBorder.CENTER</code>
 468      *<li><code>TitledBorder.RIGHT</code>
 469      *<li><code>TitledBorder.LEADING</code>
 470      *<li><code>TitledBorder.TRAILING</code>
 471      *<li><code>TitledBorder.DEFAULT_JUSTIFICATION</code> (leading)
 472      *</ul>
 473      * @param titlePosition       an integer specifying the vertical position of
 474      *        the text in relation to the border -- one of the following:
 475      *<ul>
 476      *<li><code> TitledBorder.ABOVE_TOP</code>
 477      *<li><code>TitledBorder.TOP</code> (sitting on the top line)
 478      *<li><code>TitledBorder.BELOW_TOP</code>
 479      *<li><code>TitledBorder.ABOVE_BOTTOM</code>
 480      *<li><code>TitledBorder.BOTTOM</code> (sitting on the bottom line)
 481      *<li><code>TitledBorder.BELOW_BOTTOM</code>
 482      *<li><code>TitledBorder.DEFAULT_POSITION</code> (the title position
 483      *  is determined by the current look and feel)
 484      *</ul>
 485      * @param titleFont           a Font object specifying the title font
 486      * @return the TitledBorder object
 487      */
 488     public static TitledBorder createTitledBorder(Border border,
 489                         String title,
 490                         int titleJustification,
 491                         int titlePosition,
 492                         Font titleFont) {
 493         return new TitledBorder(border, title, titleJustification,
 494                         titlePosition, titleFont);
 495     }
 496 
 497     /**
 498      * Adds a title to an existing border, with the specified
 499      * positioning, font and color.
 500      *
 501      * @param border      the <code>Border</code> object to add the title to
 502      * @param title       a <code>String</code> containing the text of the title
 503      * @param titleJustification  an integer specifying the justification
 504      *        of the title -- one of the following:
 505      *<ul>
 506      *<li><code>TitledBorder.LEFT</code>
 507      *<li><code>TitledBorder.CENTER</code>
 508      *<li><code>TitledBorder.RIGHT</code>
 509      *<li><code>TitledBorder.LEADING</code>
 510      *<li><code>TitledBorder.TRAILING</code>
 511      *<li><code>TitledBorder.DEFAULT_JUSTIFICATION</code> (leading)
 512      *</ul>
 513      * @param titlePosition       an integer specifying the vertical position of
 514      *        the text in relation to the border -- one of the following:
 515      *<ul>
 516      *<li><code> TitledBorder.ABOVE_TOP</code>
 517      *<li><code>TitledBorder.TOP</code> (sitting on the top line)
 518      *<li><code>TitledBorder.BELOW_TOP</code>
 519      *<li><code>TitledBorder.ABOVE_BOTTOM</code>
 520      *<li><code>TitledBorder.BOTTOM</code> (sitting on the bottom line)
 521      *<li><code>TitledBorder.BELOW_BOTTOM</code>
 522      *<li><code>TitledBorder.DEFAULT_POSITION</code> (the title position
 523      *  is determined by the current look and feel)
 524      *</ul>
 525      * @param titleFont   a <code>Font</code> object specifying the title font
 526      * @param titleColor  a <code>Color</code> object specifying the title color
 527      * @return the <code>TitledBorder</code> object
 528      */
 529     public static TitledBorder createTitledBorder(Border border,
 530                         String title,
 531                         int titleJustification,
 532                         int titlePosition,
 533                         Font titleFont,
 534                         Color titleColor)       {
 535         return new TitledBorder(border, title, titleJustification,
 536                         titlePosition, titleFont, titleColor);
 537     }
 538 //// EmptyBorder ///////////////////////////////////////////////////////////
 539     static final Border emptyBorder = new EmptyBorder(0, 0, 0, 0);
 540 
 541     /**
 542      * Creates an empty border that takes up no space. (The width
 543      * of the top, bottom, left, and right sides are all zero.)
 544      *
 545      * @return the <code>Border</code> object
 546      */
 547     public static Border createEmptyBorder() {
 548         return emptyBorder;
 549     }
 550 
 551     /**
 552      * Creates an empty border that takes up space but which does
 553      * no drawing, specifying the width of the top, left, bottom, and
 554      * right sides.
 555      *
 556      * @param top     an integer specifying the width of the top,
 557      *                  in pixels
 558      * @param left    an integer specifying the width of the left side,
 559      *                  in pixels
 560      * @param bottom  an integer specifying the width of the bottom,
 561      *                  in pixels
 562      * @param right   an integer specifying the width of the right side,
 563      *                  in pixels
 564      * @return the <code>Border</code> object
 565      */
 566     public static Border createEmptyBorder(int top, int left,
 567                                                 int bottom, int right) {
 568         return new EmptyBorder(top, left, bottom, right);
 569     }
 570 
 571 //// CompoundBorder ////////////////////////////////////////////////////////
 572     /**
 573      * Creates a compound border with a <code>null</code> inside edge and a
 574      * <code>null</code> outside edge.
 575      *
 576      * @return the <code>CompoundBorder</code> object
 577      */
 578     public static CompoundBorder createCompoundBorder() {
 579         return new CompoundBorder();
 580     }
 581 
 582     /**
 583      * Creates a compound border specifying the border objects to use
 584      * for the outside and inside edges.
 585      *
 586      * @param outsideBorder  a <code>Border</code> object for the outer
 587      *                          edge of the compound border
 588      * @param insideBorder   a <code>Border</code> object for the inner
 589      *                          edge of the compound border
 590      * @return the <code>CompoundBorder</code> object
 591      */
 592     public static CompoundBorder createCompoundBorder(Border outsideBorder,
 593                                                 Border insideBorder) {
 594         return new CompoundBorder(outsideBorder, insideBorder);
 595     }
 596 
 597 //// MatteBorder ////////////////////////////////////////////////////////
 598     /**
 599      * Creates a matte-look border using a solid color. (The difference between
 600      * this border and a line border is that you can specify the individual
 601      * border dimensions.)
 602      *
 603      * @param top     an integer specifying the width of the top,
 604      *                          in pixels
 605      * @param left    an integer specifying the width of the left side,
 606      *                          in pixels
 607      * @param bottom  an integer specifying the width of the right side,
 608      *                          in pixels
 609      * @param right   an integer specifying the width of the bottom,
 610      *                          in pixels
 611      * @param color   a <code>Color</code> to use for the border
 612      * @return the <code>MatteBorder</code> object
 613      */
 614     public static MatteBorder createMatteBorder(int top, int left, int bottom, int right,
 615                                                 Color color) {
 616         return new MatteBorder(top, left, bottom, right, color);
 617     }
 618 
 619     /**
 620      * Creates a matte-look border that consists of multiple tiles of a
 621      * specified icon. Multiple copies of the icon are placed side-by-side
 622      * to fill up the border area.
 623      * <p>
 624      * Note:<br>
 625      * If the icon doesn't load, the border area is painted gray.
 626      *
 627      * @param top     an integer specifying the width of the top,
 628      *                          in pixels
 629      * @param left    an integer specifying the width of the left side,
 630      *                          in pixels
 631      * @param bottom  an integer specifying the width of the right side,
 632      *                          in pixels
 633      * @param right   an integer specifying the width of the bottom,
 634      *                          in pixels
 635      * @param tileIcon  the <code>Icon</code> object used for the border tiles
 636      * @return the <code>MatteBorder</code> object
 637      */
 638     public static MatteBorder createMatteBorder(int top, int left, int bottom, int right,
 639                                                 Icon tileIcon) {
 640         return new MatteBorder(top, left, bottom, right, tileIcon);
 641     }
 642 
 643 //// StrokeBorder //////////////////////////////////////////////////////////////
 644 ////////////////////////////////////////////////////////////////////////////////
 645 
 646     /**
 647      * Creates a border of the specified {@code stroke}.
 648      * The component's foreground color will be used to render the border.
 649      *
 650      * @param stroke  the {@link BasicStroke} object used to stroke a shape
 651      * @return the {@code Border} object
 652      *
 653      * @throws NullPointerException if the specified {@code stroke} is {@code null}
 654      *
 655      * @since 1.7
 656      */




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javax.swing;
  26 
  27 import java.awt.BasicStroke;
  28 import java.awt.Color;
  29 import java.awt.Font;
  30 import java.awt.Paint;
  31 import javax.swing.border.*;
  32 
  33 /**
  34  * Factory class for vending standard {@code Border} objects.  Wherever
  35  * possible, this factory will hand out references to shared
  36  * {@code Border} instances.
  37  * For further information and examples see
  38  * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/border.html">How
  39  to Use Borders</a>,
  40  * a section in <em>The Java Tutorial</em>.
  41  *
  42  * @author David Kloba
  43  * @since 1.2
  44  */
  45 public class BorderFactory
  46 {
  47 
  48     /** Don't let anyone instantiate this class */
  49     private BorderFactory() {
  50     }
  51 
  52 
  53 //// LineBorder ///////////////////////////////////////////////////////////////
  54     /**
  55      * Creates a line border withe the specified color.
  56      *
  57      * @param color  a {@code Color} to use for the line
  58      * @return the {@code Border} object
  59      */
  60     public static Border createLineBorder(Color color) {
  61         return new LineBorder(color, 1);
  62     }
  63 
  64     /**
  65      * Creates a line border with the specified color
  66      * and width. The width applies to all four sides of the
  67      * border. To specify widths individually for the top,
  68      * bottom, left, and right, use
  69      * {@link #createMatteBorder(int,int,int,int,Color)}.
  70      *
  71      * @param color  a {@code Color} to use for the line
  72      * @param thickness  an integer specifying the width in pixels
  73      * @return the {@code Border} object
  74      */
  75     public static Border createLineBorder(Color color, int thickness)  {
  76         return new LineBorder(color, thickness);
  77     }
  78 
  79     /**
  80      * Creates a line border with the specified color, thickness, and corner shape.
  81      *
  82      * @param color      the color of the border
  83      * @param thickness  the thickness of the border
  84      * @param rounded    whether or not border corners should be round
  85      * @return the {@code Border} object
  86      *
  87      * @see LineBorder#LineBorder(Color, int, boolean)
  88      * @since 1.7
  89      */
  90     public static Border createLineBorder(Color color, int thickness, boolean rounded) {
  91         return new LineBorder(color, thickness, rounded);
  92     }
  93 
  94 //// BevelBorder /////////////////////////////////////////////////////////////
  95 ///////////////////////////////////////////////////////////////////////////////
  96     static final Border sharedRaisedBevel = new BevelBorder(BevelBorder.RAISED);
  97     static final Border sharedLoweredBevel = new BevelBorder(BevelBorder.LOWERED);
  98 
  99     /**
 100      * Creates a border with a raised beveled edge, using
 101      * brighter shades of the component's current background color
 102      * for highlighting, and darker shading for shadows.
 103      * (In a raised border, highlights are on top and shadows
 104      *  are underneath.)
 105      *
 106      * @return the {@code Border} object
 107      */
 108     public static Border createRaisedBevelBorder() {
 109         return createSharedBevel(BevelBorder.RAISED);
 110     }
 111 
 112     /**
 113      * Creates a border with a lowered beveled edge, using
 114      * brighter shades of the component's current background color
 115      * for highlighting, and darker shading for shadows.
 116      * (In a lowered border, shadows are on top and highlights
 117      *  are underneath.)
 118      *
 119      * @return the {@code Border} object
 120      */
 121     public static Border createLoweredBevelBorder() {
 122         return createSharedBevel(BevelBorder.LOWERED);
 123     }
 124 
 125     /**
 126      * Creates a beveled border of the specified type, using
 127      * brighter shades of the component's current background color
 128      * for highlighting, and darker shading for shadows.
 129      * (In a lowered border, shadows are on top and highlights
 130      *  are underneath.)
 131      *
 132      * @param type  an integer specifying either
 133      *                  {@code BevelBorder.LOWERED} or
 134      *                  {@code BevelBorder.RAISED}
 135      * @return the {@code Border} object
 136      */
 137     public static Border createBevelBorder(int type) {
 138         return createSharedBevel(type);
 139     }
 140 
 141     /**
 142      * Creates a beveled border of the specified type, using
 143      * the specified highlighting and shadowing. The outer
 144      * edge of the highlighted area uses a brighter shade of
 145      * the highlight color. The inner edge of the shadow area
 146      * uses a brighter shade of the shadow color.
 147      *
 148      * @param type  an integer specifying either
 149      *                  {@code BevelBorder.LOWERED} or
 150      *                  {@code BevelBorder.RAISED}
 151      * @param highlight  a {@code Color} object for highlights
 152      * @param shadow     a {@code Color} object for shadows
 153      * @return the {@code Border} object
 154      */
 155     public static Border createBevelBorder(int type, Color highlight, Color shadow) {
 156         return new BevelBorder(type, highlight, shadow);
 157     }
 158 
 159     /**
 160      * Creates a beveled border of the specified type, using
 161      * the specified colors for the inner and outer highlight
 162      * and shadow areas.
 163      *
 164      * @param type  an integer specifying either
 165      *          {@code BevelBorder.LOWERED} or
 166      *          {@code BevelBorder.RAISED}
 167      * @param highlightOuter  a {@code Color} object for the
 168      *                  outer edge of the highlight area
 169      * @param highlightInner  a {@code Color} object for the
 170      *                  inner edge of the highlight area
 171      * @param shadowOuter     a {@code Color} object for the
 172      *                  outer edge of the shadow area
 173      * @param shadowInner     a {@code Color} object for the
 174      *                  inner edge of the shadow area
 175      * @return the {@code Border} object
 176      */
 177     public static Border createBevelBorder(int type,
 178                         Color highlightOuter, Color highlightInner,
 179                         Color shadowOuter, Color shadowInner) {
 180         return new BevelBorder(type, highlightOuter, highlightInner,
 181                                         shadowOuter, shadowInner);
 182     }
 183 
 184     static Border createSharedBevel(int type)   {
 185         if(type == BevelBorder.RAISED) {
 186             return sharedRaisedBevel;
 187         } else if(type == BevelBorder.LOWERED) {
 188             return sharedLoweredBevel;
 189         }
 190         return null;
 191     }
 192 
 193 //// SoftBevelBorder ///////////////////////////////////////////////////////////
 194 ////////////////////////////////////////////////////////////////////////////////
 195 


 289      * @param shadowInner     a color of the inner edge of the shadow area
 290      * @return the {@code Border} object
 291      *
 292      * @see BevelBorder#BevelBorder(int, Color, Color, Color, Color)
 293      * @since 1.7
 294      */
 295     public static Border createSoftBevelBorder(int type, Color highlightOuter, Color highlightInner, Color shadowOuter, Color shadowInner) {
 296         return new SoftBevelBorder(type, highlightOuter, highlightInner, shadowOuter, shadowInner);
 297     }
 298 
 299 //// EtchedBorder ///////////////////////////////////////////////////////////
 300 
 301     static final Border sharedEtchedBorder = new EtchedBorder();
 302     private static Border sharedRaisedEtchedBorder;
 303 
 304     /**
 305      * Creates a border with an "etched" look using
 306      * the component's current background color for
 307      * highlighting and shading.
 308      *
 309      * @return the {@code Border} object
 310      */
 311     public static Border createEtchedBorder()    {
 312         return sharedEtchedBorder;
 313     }
 314 
 315     /**
 316      * Creates a border with an "etched" look using
 317      * the specified highlighting and shading colors.
 318      *
 319      * @param highlight  a {@code Color} object for the border highlights
 320      * @param shadow     a {@code Color} object for the border shadows
 321      * @return the {@code Border} object
 322      */
 323     public static Border createEtchedBorder(Color highlight, Color shadow)    {
 324         return new EtchedBorder(highlight, shadow);
 325     }
 326 
 327     /**
 328      * Creates a border with an "etched" look using
 329      * the component's current background color for
 330      * highlighting and shading.
 331      *
 332      * @param type      one of {@code EtchedBorder.RAISED}, or
 333      *                  {@code EtchedBorder.LOWERED}
 334      * @return the {@code Border} object
 335      * @exception IllegalArgumentException if type is not either
 336      *                  {@code EtchedBorder.RAISED} or
 337      *                  {@code EtchedBorder.LOWERED}
 338      * @since 1.3
 339      */
 340     public static Border createEtchedBorder(int type)    {
 341         switch (type) {
 342         case EtchedBorder.RAISED:
 343             if (sharedRaisedEtchedBorder == null) {
 344                 sharedRaisedEtchedBorder = new EtchedBorder
 345                                            (EtchedBorder.RAISED);
 346             }
 347             return sharedRaisedEtchedBorder;
 348         case EtchedBorder.LOWERED:
 349             return sharedEtchedBorder;
 350         default:
 351             throw new IllegalArgumentException("type must be one of EtchedBorder.RAISED or EtchedBorder.LOWERED");
 352         }
 353     }
 354 
 355     /**
 356      * Creates a border with an "etched" look using
 357      * the specified highlighting and shading colors.
 358      *
 359      * @param type      one of {@code EtchedBorder.RAISED}, or
 360      *                  {@code EtchedBorder.LOWERED}
 361      * @param highlight  a {@code Color} object for the border highlights
 362      * @param shadow     a {@code Color} object for the border shadows
 363      * @return the {@code Border} object
 364      * @since 1.3
 365      */
 366     public static Border createEtchedBorder(int type, Color highlight,
 367                                             Color shadow)    {
 368         return new EtchedBorder(type, highlight, shadow);
 369     }
 370 
 371 //// TitledBorder ////////////////////////////////////////////////////////////
 372     /**
 373      * Creates a new titled border with the specified title,
 374      * the default border type (determined by the current look and feel),
 375      * the default text position (determined by the current look and feel),
 376      * the default justification (leading), and the default
 377      * font and text color (determined by the current look and feel).
 378      *
 379      * @param title      a {@code String} containing the text of the title
 380      * @return the {@code TitledBorder} object
 381      */
 382     public static TitledBorder createTitledBorder(String title)     {
 383         return new TitledBorder(title);
 384     }
 385 
 386     /**
 387      * Creates a new titled border with an empty title,
 388      * the specified border object,
 389      * the default text position (determined by the current look and feel),
 390      * the default justification (leading), and the default
 391      * font and text color (determined by the current look and feel).
 392      *
 393      * @param border     the {@code Border} object to add the title to; if
 394      *                   {@code null} the {@code Border} is determined
 395      *                   by the current look and feel.
 396      * @return the {@code TitledBorder} object
 397      */
 398     public static TitledBorder createTitledBorder(Border border)       {
 399         return new TitledBorder(border);
 400     }
 401 
 402     /**
 403      * Adds a title to an existing border,
 404      * with default positioning (determined by the current look and feel),
 405      * default justification (leading) and the default
 406      * font and text color (determined by the current look and feel).
 407      *
 408      * @param border     the {@code Border} object to add the title to
 409      * @param title      a {@code String} containing the text of the title
 410      * @return the {@code TitledBorder} object
 411      */
 412     public static TitledBorder createTitledBorder(Border border,
 413                                                    String title) {
 414         return new TitledBorder(border, title);
 415     }
 416 
 417     /**
 418      * Adds a title to an existing border, with the specified
 419      * positioning and using the default
 420      * font and text color (determined by the current look and feel).
 421      *
 422      * @param border      the {@code Border} object to add the title to
 423      * @param title       a {@code String} containing the text of the title
 424      * @param titleJustification  an integer specifying the justification
 425      *        of the title -- one of the following:
 426      *<ul>
 427      *<li>{@code TitledBorder.LEFT}
 428      *<li>{@code TitledBorder.CENTER}
 429      *<li>{@code TitledBorder.RIGHT}
 430      *<li>{@code TitledBorder.LEADING}
 431      *<li>{@code TitledBorder.TRAILING}
 432      *<li>{@code TitledBorder.DEFAULT_JUSTIFICATION} (leading)
 433      *</ul>
 434      * @param titlePosition       an integer specifying the vertical position of
 435      *        the text in relation to the border -- one of the following:
 436      *<ul>
 437      *<li>{@code TitledBorder.ABOVE_TOP}
 438      *<li>{@code TitledBorder.TOP} (sitting on the top line)
 439      *<li>{@code TitledBorder.BELOW_TOP}
 440      *<li>{@code TitledBorder.ABOVE_BOTTOM}
 441      *<li>{@code TitledBorder.BOTTOM} (sitting on the bottom line)
 442      *<li>{@code TitledBorder.BELOW_BOTTOM}
 443      *<li>{@code TitledBorder.DEFAULT_POSITION} (the title position
 444      *  is determined by the current look and feel)
 445      *</ul>
 446      * @return the {@code TitledBorder} object
 447      */
 448     public static TitledBorder createTitledBorder(Border border,
 449                         String title,
 450                         int titleJustification,
 451                         int titlePosition)      {
 452         return new TitledBorder(border, title, titleJustification,
 453                         titlePosition);
 454     }
 455 
 456     /**
 457      * Adds a title to an existing border, with the specified
 458      * positioning and font, and using the default text color
 459      * (determined by the current look and feel).
 460      *
 461      * @param border      the {@code Border} object to add the title to
 462      * @param title       a {@code String} containing the text of the title
 463      * @param titleJustification  an integer specifying the justification
 464      *        of the title -- one of the following:
 465      *<ul>
 466      *<li>{@code TitledBorder.LEFT}
 467      *<li>{@code TitledBorder.CENTER}
 468      *<li>{@code TitledBorder.RIGHT}
 469      *<li>{@code TitledBorder.LEADING}
 470      *<li>{@code TitledBorder.TRAILING}
 471      *<li>{@code TitledBorder.DEFAULT_JUSTIFICATION} (leading)
 472      *</ul>
 473      * @param titlePosition       an integer specifying the vertical position of
 474      *        the text in relation to the border -- one of the following:
 475      *<ul>
 476      *<li>{@code TitledBorder.ABOVE_TOP}
 477      *<li>{@code TitledBorder.TOP} (sitting on the top line)
 478      *<li>{@code TitledBorder.BELOW_TOP}
 479      *<li>{@code TitledBorder.ABOVE_BOTTOM}
 480      *<li>{@code TitledBorder.BOTTOM} (sitting on the bottom line)
 481      *<li>{@code TitledBorder.BELOW_BOTTOM}
 482      *<li>{@code TitledBorder.DEFAULT_POSITION} (the title position
 483      *  is determined by the current look and feel)
 484      *</ul>
 485      * @param titleFont           a Font object specifying the title font
 486      * @return the TitledBorder object
 487      */
 488     public static TitledBorder createTitledBorder(Border border,
 489                         String title,
 490                         int titleJustification,
 491                         int titlePosition,
 492                         Font titleFont) {
 493         return new TitledBorder(border, title, titleJustification,
 494                         titlePosition, titleFont);
 495     }
 496 
 497     /**
 498      * Adds a title to an existing border, with the specified
 499      * positioning, font and color.
 500      *
 501      * @param border      the {@code Border} object to add the title to
 502      * @param title       a {@code String} containing the text of the title
 503      * @param titleJustification  an integer specifying the justification
 504      *        of the title -- one of the following:
 505      *<ul>
 506      *<li>{@code TitledBorder.LEFT}
 507      *<li>{@code TitledBorder.CENTER}
 508      *<li>{@code TitledBorder.RIGHT}
 509      *<li>{@code TitledBorder.LEADING}
 510      *<li>{@code TitledBorder.TRAILING}
 511      *<li>{@code TitledBorder.DEFAULT_JUSTIFICATION} (leading)
 512      *</ul>
 513      * @param titlePosition       an integer specifying the vertical position of
 514      *        the text in relation to the border -- one of the following:
 515      *<ul>
 516      *<li>{@code TitledBorder.ABOVE_TOP}
 517      *<li>{@code TitledBorder.TOP} (sitting on the top line)
 518      *<li>{@code TitledBorder.BELOW_TOP}
 519      *<li>{@code TitledBorder.ABOVE_BOTTOM}
 520      *<li>{@code TitledBorder.BOTTOM} (sitting on the bottom line)
 521      *<li>{@code TitledBorder.BELOW_BOTTOM}
 522      *<li>{@code TitledBorder.DEFAULT_POSITION} (the title position
 523      *  is determined by the current look and feel)
 524      *</ul>
 525      * @param titleFont   a {@code Font} object specifying the title font
 526      * @param titleColor  a {@code Color} object specifying the title color
 527      * @return the {@code TitledBorder} object
 528      */
 529     public static TitledBorder createTitledBorder(Border border,
 530                         String title,
 531                         int titleJustification,
 532                         int titlePosition,
 533                         Font titleFont,
 534                         Color titleColor)       {
 535         return new TitledBorder(border, title, titleJustification,
 536                         titlePosition, titleFont, titleColor);
 537     }
 538 //// EmptyBorder ///////////////////////////////////////////////////////////
 539     static final Border emptyBorder = new EmptyBorder(0, 0, 0, 0);
 540 
 541     /**
 542      * Creates an empty border that takes up no space. (The width
 543      * of the top, bottom, left, and right sides are all zero.)
 544      *
 545      * @return the {@code Border} object
 546      */
 547     public static Border createEmptyBorder() {
 548         return emptyBorder;
 549     }
 550 
 551     /**
 552      * Creates an empty border that takes up space but which does
 553      * no drawing, specifying the width of the top, left, bottom, and
 554      * right sides.
 555      *
 556      * @param top     an integer specifying the width of the top,
 557      *                  in pixels
 558      * @param left    an integer specifying the width of the left side,
 559      *                  in pixels
 560      * @param bottom  an integer specifying the width of the bottom,
 561      *                  in pixels
 562      * @param right   an integer specifying the width of the right side,
 563      *                  in pixels
 564      * @return the {@code Border} object
 565      */
 566     public static Border createEmptyBorder(int top, int left,
 567                                                 int bottom, int right) {
 568         return new EmptyBorder(top, left, bottom, right);
 569     }
 570 
 571 //// CompoundBorder ////////////////////////////////////////////////////////
 572     /**
 573      * Creates a compound border with a {@code null} inside edge and a
 574      * {@code null} outside edge.
 575      *
 576      * @return the {@code CompoundBorder} object
 577      */
 578     public static CompoundBorder createCompoundBorder() {
 579         return new CompoundBorder();
 580     }
 581 
 582     /**
 583      * Creates a compound border specifying the border objects to use
 584      * for the outside and inside edges.
 585      *
 586      * @param outsideBorder  a {@code Border} object for the outer
 587      *                          edge of the compound border
 588      * @param insideBorder   a {@code Border} object for the inner
 589      *                          edge of the compound border
 590      * @return the {@code CompoundBorder} object
 591      */
 592     public static CompoundBorder createCompoundBorder(Border outsideBorder,
 593                                                 Border insideBorder) {
 594         return new CompoundBorder(outsideBorder, insideBorder);
 595     }
 596 
 597 //// MatteBorder ////////////////////////////////////////////////////////
 598     /**
 599      * Creates a matte-look border using a solid color. (The difference between
 600      * this border and a line border is that you can specify the individual
 601      * border dimensions.)
 602      *
 603      * @param top     an integer specifying the width of the top,
 604      *                          in pixels
 605      * @param left    an integer specifying the width of the left side,
 606      *                          in pixels
 607      * @param bottom  an integer specifying the width of the right side,
 608      *                          in pixels
 609      * @param right   an integer specifying the width of the bottom,
 610      *                          in pixels
 611      * @param color   a {@code Color} to use for the border
 612      * @return the {@code MatteBorder} object
 613      */
 614     public static MatteBorder createMatteBorder(int top, int left, int bottom, int right,
 615                                                 Color color) {
 616         return new MatteBorder(top, left, bottom, right, color);
 617     }
 618 
 619     /**
 620      * Creates a matte-look border that consists of multiple tiles of a
 621      * specified icon. Multiple copies of the icon are placed side-by-side
 622      * to fill up the border area.
 623      * <p>
 624      * Note:<br>
 625      * If the icon doesn't load, the border area is painted gray.
 626      *
 627      * @param top     an integer specifying the width of the top,
 628      *                          in pixels
 629      * @param left    an integer specifying the width of the left side,
 630      *                          in pixels
 631      * @param bottom  an integer specifying the width of the right side,
 632      *                          in pixels
 633      * @param right   an integer specifying the width of the bottom,
 634      *                          in pixels
 635      * @param tileIcon  the {@code Icon} object used for the border tiles
 636      * @return the {@code MatteBorder} object
 637      */
 638     public static MatteBorder createMatteBorder(int top, int left, int bottom, int right,
 639                                                 Icon tileIcon) {
 640         return new MatteBorder(top, left, bottom, right, tileIcon);
 641     }
 642 
 643 //// StrokeBorder //////////////////////////////////////////////////////////////
 644 ////////////////////////////////////////////////////////////////////////////////
 645 
 646     /**
 647      * Creates a border of the specified {@code stroke}.
 648      * The component's foreground color will be used to render the border.
 649      *
 650      * @param stroke  the {@link BasicStroke} object used to stroke a shape
 651      * @return the {@code Border} object
 652      *
 653      * @throws NullPointerException if the specified {@code stroke} is {@code null}
 654      *
 655      * @since 1.7
 656      */


< prev index next >