Java JPanel two borders, different colors?

border, java, swing

Solution

Use a `CompoundBorder`

ie...

pnlTop.setBorder(new CompoundBorder(
    BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLUE), 
    BorderFactory.createMatteBorder(0, 0, 1, 0, Color.RED));

See How to use Borders for more details

Problem

For my layout i want to have double borders, on the bottom of my JPanel, one should be slightly darker and the other should be slightly lighter. Currently i have 1 border: ``` JPanel pnlTop = new JPanel(new BorderLayout()) { protected void paintComponent(Graphics grphcs) { super.paintComponent(grphcs); Graphics2D g2d = (Graphics2D) grphcs; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); GradientPaint gp = new GradientPaint(0, 0, new java.awt.Color(237, 237, 237), 0, getHeight(), new java.awt.Color(222, 222, 222)); g2d.setPaint(gp); g2d.fillRect(0, 0, getWidth(), getHeight()); } }; pnlTop.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(173, 173, 166))); pnlTop.setPreferredSize(new Dimension(2000, 90)); add(pnlTop, BorderLayout.PAGE_START); ``` How could i add another border underneath the one that i already have? Is this possible?

Original source