JPanels and Borders
Optional Reading
We will be using the Creating a GUI with JFC/Swing tutorial from Sun as a Reference source. You are not required to read the entire tutorial, I suggest you skim through it though to use a a supplement to what I give you here.
JPanel Basics
JPanel is your basic container for Swing. It isn't very exciting, it's just a basic building block used in some way or another for every Swing app.
We've actually seen the JPanel several times so far, in the Java2D section, and some in others. JPanels are transparent unless you set the background color with setBackground().
Borders
Don't get confused, Borders are not just for JPanels. Borders can be used for any component subclassed from JComponent, which is almost everything that can be drawn to the screen except the Primary/Secondary application windows.
A Border is just a method which knows how to draw some type of border around an object, any object.
Since Border is actually just an interface. The JDK has a number of concrete classes which implement the interface in different ways
Swing provides a class specifically for creating borders. This is a "Factory" class for vending standard Border objects. Where ever possible, this factory will hand out references to shared Border instances.
JPanel myPanel = new JPanel();
myPanel.setBorder(BorderFactory.createRaisedBevelBorder());
As you can see from above, once you have a Border you have a component use it by using the setBorder() method.
Download and open the Netbeans project borders. This application brings up several different border types as shown below.