Java Swing BorderLayout addBorders(Component content)

Here you can find the source of addBorders(Component content)

Description

add Borders

License

Open Source License

Declaration

static Component addBorders(Component content) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Main {
    final static Color CYAN = new Color(99, 158, 255);
    public final static Color BLUE = new Color(49, 97, 206);

    static Component addBorders(Component content) {
        JPanel panel = new JPanel();
        BoxLayout boxLayout1 = new BoxLayout(panel, BoxLayout.Y_AXIS);
        panel.setLayout(boxLayout1);//from   w ww .  j  a  va2  s .  c o  m
        panel.setBackground(CYAN);

        JPanel topPanel = new JPanel();
        topPanel.setPreferredSize(new Dimension((int) content.getPreferredSize().getWidth() + 5, 5));
        topPanel.setLayout(new BorderLayout());
        topPanel.setBackground(BLUE);

        JLabel nwCorner = new JLabel();
        ImageIcon nwIcon = new ImageIcon("files/img/nw.png");
        nwCorner.setIcon(nwIcon);
        topPanel.add(nwCorner, BorderLayout.WEST);

        JLabel neCorner = new JLabel();
        ImageIcon neIcon = new ImageIcon("files/img/ne.png");
        neCorner.setIcon(neIcon);
        topPanel.add(neCorner, BorderLayout.EAST);
        panel.add(topPanel);

        JPanel contentPanel = new JPanel();
        contentPanel.setBackground(BLUE);
        contentPanel.add(content);
        panel.add(content);

        JPanel downPanel = new JPanel();
        downPanel.setPreferredSize(new Dimension((int) content.getPreferredSize().getWidth(), 5));
        downPanel.setLayout(new BorderLayout());
        downPanel.setBackground(BLUE);

        JLabel swCorner = new JLabel();
        ImageIcon swIcon = new ImageIcon("files/img/sw.png");
        swCorner.setIcon(swIcon);
        downPanel.add(swCorner, BorderLayout.WEST);

        JLabel seCorner = new JLabel();
        ImageIcon seIcon = new ImageIcon("files/img/se.png");
        seCorner.setIcon(seIcon);
        downPanel.add(seCorner, BorderLayout.EAST);
        panel.add(downPanel);
        return panel;
    }
}

Related

  1. addToPanel(JPanel panel, JComponent centerComponent, JComponent arrangedComponent, String borderLayoutConstraint)
  2. addToVerticalBorderLayout(JComponent north, JComponent center, JComponent south)
  3. createBorderLayoutPane(Object... args)
  4. createBox(Border border, Component center, Component north)