JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createLineBorder(Color.black));
JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createTitledBorder("My Panel"));
JPanel panel = new JPanel(); Border blackLine = BorderFactory.createLineBorder(Color.black); Border empty = BorderFactory.createEmptyBorder(10, 10, 10, 10); Border compound = BorderFactory.createCompoundBorder(blackLine, empty); panel.setBorder(compound);This code creates a new JPanel and sets its border to a compound border, which is made up of a black line border and an empty border with 10 pixels of padding on all sides. The setBorder method is part of the javax.swing package library.