Copyright Derek O'Reilly, Dundalk Institute of Technology (DkIT), Dundalk, Co. Louth, Ireland.
A Border can be placed on any Component. The example below shows some basic Borders.
BorderDemo example: (Run Applet)
import java.awt.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; public class BorderDemo extends JApplet { @Override public void init() { this.setContentPane(new View()); } public class View extends JPanel implements ListSelectionListener { private final ImageIcon smiley = new ImageIcon(getClass().getClassLoader().getResource("images/smiley.jpg")); private final Border borders[] = { BorderFactory.createEmptyBorder(), BorderFactory.createEtchedBorder(), BorderFactory.createLineBorder(Color.red), BorderFactory.createLoweredBevelBorder(), BorderFactory.createMatteBorder(4, 4, 2, 2, Color.gray), // top, left, bottom, right BorderFactory.createRaisedBevelBorder(), BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.green), "Title", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION), BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()), BorderFactory.createMatteBorder(10, 10, 10, 10, this.smiley) }; private final String borderNames[] = { "Empty", "Etched", "Line", "Lowered Bevel", "Matt", "Raised Bevel", "Titled", "Compound", "icon" }; private final JList borderList = new JList(this.borderNames); public View() { super(); this.borderList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); this.add(this.borderList); this.borderList.addListSelectionListener(this); } @Override public void valueChanged(ListSelectionEvent e) { this.borderList.setBorder(this.borders[this.borderList.getSelectedIndex()]); } } }
Copyright Derek O' Reilly, Dundalk Institute of Technology (DkIT), Dundalk, Co. Louth, Ireland.