The
JComponent also includes a method called SetBorder (), which allows us to place a variety of interesting borders onto some visible components. The following program example uses a method called Showborder () that creates jpanel and places a border into each example, demonstrating some useful different borders. Again, it uses Rtti to find the name of the border we use (culling all the path information), and then place the border name in the middle of the jlable:
: Borders.java//different Swing Borders package c13.swing;
Import java.awt.*;
Import java.awt.event.*;
Import javax.swing.*;
Import javax.swing.border.*;
public class Borders extends JPanel {static JPanel Showborder (Border b) {JPanel JP = new JPanel ();
Jp.setlayout (New BorderLayout ());
String nm = B.getclass (). toString ();
NM = nm.substring (Nm.lastindexof ('. ') + 1);
Jp.add (New JLabel (nm, jlabel.center), borderlayout.center);
Jp.setborder (b);
return JP;
Public Borders () {setlayout (new GridLayout (2,4));
Add (Showborder ("Title")) (new Titledborder);
Add (Showborder (new Etchedborder ()));
Add (Showborder (new Lineborder (Color.Blue));
Add (Showborder (new Matteborder (5,5,30,30,color.green));
Add (Showborder (new BevelBorder (bevelborder.raised));
Add (Showborder (new Softbevelborder (bevelborder.lowered)); Add (Showborder (New Compoundborder (), New Etchedborder (), New Lineborder (color.red))));
public static void Main (String args[]) {show.inframe (New Borders (), 500, 300); }
} ///:~
Most of the program examples in this section use Titledborder, but we can note that the rest of the borders are also easy to use. Can create our own borders and place them into buttons, tags, and so on--anything from jcomponent.