An extension of the answer given by Yanfleya, where you create the “opposite” of two different panels to reproduce the appearance of the engraved border.
You can create it in one panel using CompoundBorder
, for example:
CompoundBorder border = BorderFactory.createCompoundBorder( BorderFactory.createMatteBorder(0, 0, 1, 0, Color.WHITE), BorderFactory.createMatteBorder(0, 0, 1, 0, Color.GRAY) );
The advantage of this method is that you can also do two sides, which then look like this: (Note that this is just a grid of nine panels and only the middle has a border that is also thicker than 1 See the code below, I used setBackground on panels to show where each panel was))
!
import javax.swing.*; import java.awt.*; public class Test { public static void main(String[] args) { JFrame f = new JFrame("A Demo"); f.setLayout(new GridLayout(3,3)); f.setSize(400,400); JPanel j1 = new JPanel();
source share