Search code examples
javaswingbordertitled-border

Difference between new xxxBorder() and Borderfactory method?


What is the difference between

setBorder(new TitledBorder(""));

and

setBorder(BorderFactory.createTitledBorder(""));

and which advantages/disadvantages do they have?


Solution

  • BorderFactory actually might not create new instances each time you call it, but return a reference to an existing one, therefore saving some resources. See also the javadoc.

    You can also check out the actual implementation if you really want to know what's going on inside BorderFactory ;-)