Results 1 to 2 of 2
  1. #1
    newbie123 is offline Member
    Join Date
    Nov 2009
    Posts
    90
    Rep Power
    0

    Default Border vs BorderFactory

    At first blush, it appears that Border and BorderFactory do essentially the same thing. Most of the examples I have seen use BorderFactory, but why would I want to use one or the other? Did BorderFactory correct a shortcoming in Border or vice versa? "Enquiring Minds Want To Know!"

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Border vs BorderFactory

    At first blush, it appears that Border and BorderFactory do essentially the same thing
    BorderFactory creates Borders, (Border is an interface, BorderFactory a class), thus they are quite different.

    why would I want to use one or the other?
    It is a Factory class, having convenient methods for creating Borders. This is opposed to having to know the ins and outs of all the Border implementations (BevelBorder, LineBorder, etc...). Further, encapsulating the creation of these class through a Factory class allows the Factory to create and reuse instances of an object (this isn't true for all the methods of BorderFactory, but as the API states: "Wherever possible, this factory will hand out references to shared Border instances.").

    If you don't know what a Factory class is, you might wish to study up on the Factory design pattern: Factory method pattern - Wikipedia, the free encyclopedia

Similar Threads

  1. BorderFactory.createTitledBorder [Need Help!!!]
    By baobao816 in forum AWT / Swing
    Replies: 1
    Last Post: 03-16-2012, 04:20 PM
  2. Set border
    By anilkumar_vist in forum New To Java
    Replies: 1
    Last Post: 02-06-2010, 11:25 AM
  3. how can create border
    By yuen in forum AWT / Swing
    Replies: 6
    Last Post: 11-08-2009, 11:42 AM
  4. Border with LestCellRenderer
    By Gajesh Tripathi in forum AWT / Swing
    Replies: 5
    Last Post: 06-02-2009, 06:59 AM
  5. BorderFactory to set position?
    By aleplgr in forum AWT / Swing
    Replies: 2
    Last Post: 01-30-2008, 12:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •