Java Swing | BevelBorder and SoftBevelBorder - GeeksforGeeks

16 Apr, 2021
BevelBorder and SoftBevelBorder are a part of javax.swing.Border package. This package contains different Border for Components. BevelBorder is an implementation of a simple two line bevel border. Bevel Border and Soft Bevel Border are almost same but Soft Bevel Border has softened corners.Constructor for the class BevelBorder:  
BevelBorder(int Type): Creates a bevel border with the specified type and whose colors will be derived from the background color of the component passed into the paintBorder method.BevelBorder(int Type, Color h, Color s):Creates a bevel border with the specified type, highlight and shadow colors.BevelBorder(int Type, Color highlightOuterColor, Color highlightInnerColor, Color shadowOuterColor, Color shadowInnerColor):Creates a bevel border with the specified type, highlight and shadow colors.
BevelBorder(int Type): Creates a bevel border with the specified type and whose colors will be derived from the background color of the component passed into the paintBorder method.
BevelBorder(int Type, Color h, Color s):Creates a bevel border with the specified type, highlight and shadow colors.
BevelBorder(int Type, Color highlightOuterColor, Color highlightInnerColor, Color shadowOuterColor, Color shadowInnerColor):Creates a bevel border with the specified type, highlight and shadow colors.
Constructor for the class SoftBevelBorder:  
SoftBevelBorder(int Type): Creates a bevel border with the specified type and whose colors will be derived from the background color of the component passed into the paintBorder method.SoftBevelBorder(int Type, Color h, Color s): Creates a bevel border with the specified type, highlight and shadow colors.SoftBevelBorder(int Type, Color highlightOuterColor, Color highlightInnerColor, Color shadowOuterColor, Color shadowInnerColor): Creates a bevel border with the specified type, highlight and shadow colors.
SoftBevelBorder(int Type): Creates a bevel border with the specified type and whose colors will be derived from the background color of the component passed into the paintBorder method.
SoftBevelBorder(int Type, Color h, Color s): Creates a bevel border with the specified type, highlight and shadow colors.
SoftBevelBorder(int Type, Color highlightOuterColor, Color highlightInnerColor, Color shadowOuterColor, Color shadowInnerColor): Creates a bevel border with the specified type, highlight and shadow colors.
Commonly used methods are: 
 
Below programs illustrate the Bevel Border class:  
Program to create a simple bevel border with specified type: To create a bevel border, we first create a JPanel object p, all the borders will be applied to this object. The JPanel will be hosted inside the JFrame f, which is the outermost container in this program. To set the bevel border, we create 2 JLabel objects, “l” and “l1”, one for the raised type border and the other for lowered type border. The borders are applied by the function l.setBorder() and l1.setBorder(). Finally, the borders are added to the JPanel by p.add() function and the results are shown by f.show(). 
Program to create a simple bevel border with specified type: To create a bevel border, we first create a JPanel object p, all the borders will be applied to this object. The JPanel will be hosted inside the JFrame f, which is the outermost container in this program. To set the bevel border, we create 2 JLabel objects, “l” and “l1”, one for the raised type border and the other for lowered type border. The borders are applied by the function l.setBorder() and l1.setBorder(). Finally, the borders are added to the JPanel by p.add() function and the results are shown by f.show(). 
Java
// Java Program to create a simple bevel// border with specified typeimport java.awt.event.*;import java.awt.*;import javax.swing.*;import javax.swing.border.*;class bevel extends JFrame {     // frame    static JFrame f;     // main class    public static void main(String[] args)    {        // create a new frame        f = new JFrame("frame");         // create a object        bevel s = new bevel();         // create a panel        JPanel p = new JPanel();         // create a label        JLabel l = new JLabel(" this is bevel border of raised type");         // create a label        JLabel l1 = new JLabel(" this is bevel border of lowered type");         // set border for panel        l.setBorder(new BevelBorder(BevelBorder.RAISED));         // set border for label        l1.setBorder(new BevelBorder(BevelBorder.LOWERED));         // add button to panel        p.add(l1);        p.add(l);         f.add(p);         // set the size of frame        f.setSize(400, 400);         f.show();    }}
Output:  
Output:  
 Program to apply bevel border with specified colors to highlight and shadow: To create a bevel border with highlighted colors, we first create a JPanel object p, all the borders will be applied to this object. The JPanel will be hosted inside the JFrame f, which is the outermost container in this program. To set the bevel border, we create 2 JLabel objects, “l” and “l1”, one for the raised type border and the other for lowered type border. The borders are applied by the function l.setBorder() and l1.setBorder(). And the colors are passed into these constructors as parameters, for ex: Color.red etc.) Finally, the borders are added to the JPanel by p.add() function and the results are shown by f.show(). 
 
Program to apply bevel border with specified colors to highlight and shadow: To create a bevel border with highlighted colors, we first create a JPanel object p, all the borders will be applied to this object. The JPanel will be hosted inside the JFrame f, which is the outermost container in this program. To set the bevel border, we create 2 JLabel objects, “l” and “l1”, one for the raised type border and the other for lowered type border. The borders are applied by the function l.setBorder() and l1.setBorder(). And the colors are passed into these constructors as parameters, for ex: Color.red etc.) Finally, the borders are added to the JPanel by p.add() function and the results are shown by f.show(). 
Java
// java Program to  apply bevel border with// specified colors to highlight and shadowimport java.awt.event.*;import java.awt.*;import javax.swing.*;import javax.swing.border.*;class bevel1 extends JFrame {     // frame    static JFrame f;     // main class    public static void main(String[] args)    {        // create a new frame        f = new JFrame("frame");         // create a object        bevel1 s = new bevel1();         // create a panel        JPanel p = new JPanel();         // create a label        JLabel l = new JLabel(" this is bevel border of raised type");         // create a label        JLabel l1 = new JLabel(" this is bevel border of lowered type");         // set border for panel        l.setBorder(new BevelBorder(BevelBorder.RAISED, Color.red,                                                       Color.blue));         // set border for label        l1.setBorder(new BevelBorder(BevelBorder.LOWERED, Color.black,                                  Color.red, Color.pink, Color.yellow));         // add button to panel        p.add(l1);        p.add(l);         f.add(p);         // set the size of frame        f.setSize(400, 400);         f.show();    }}
Output:  
Output:  
Below programs illustrate the SoftBevelBorder class:  
Program to create a simple Soft bevel border with specified type: To create a soft bevel border, we first create a JPanel object p, all the borders will be applied to this object. The JPanel will be hosted inside the JFrame f. To set the bevel border, we create 2 JLabel objects, “l” and “l1”. The borders are applied by the function l.setBorder() and l1.setBorder(). To make the border soft, we call the constructor in the parameter of setBorder() method, which is indicated by line “new SoftBevelBorder()). Finally, the borders are added to the JPanel by p.add() function and the results are shown by f.show(). 
Program to create a simple Soft bevel border with specified type: To create a soft bevel border, we first create a JPanel object p, all the borders will be applied to this object. The JPanel will be hosted inside the JFrame f. To set the bevel border, we create 2 JLabel objects, “l” and “l1”. The borders are applied by the function l.setBorder() and l1.setBorder(). To make the border soft, we call the constructor in the parameter of setBorder() method, which is indicated by line “new SoftBevelBorder()). Finally, the borders are added to the JPanel by p.add() function and the results are shown by f.show(). 
Java
// java Program to create a simple Soft bevel border// with specified typeimport java.awt.event.*;import java.awt.*;import javax.swing.*;import javax.swing.border.*;class bevel2 extends JFrame {     // frame    static JFrame f;     // main class    public static void main(String[] args)    {        // create a new frame        f = new JFrame("frame");         // create a object        bevel2 s = new bevel2();         // create a panel        JPanel p = new JPanel();         // create a label        JLabel l = new JLabel(" this is bevel border of raised type");         // create a label        JLabel l1 = new JLabel(" this is bevel border of lowered type");         // set border for panel        l.setBorder(new SoftBevelBorder(BevelBorder.RAISED));         // set border for label        l1.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));         // add button to panel        p.add(l1);        p.add(l);         f.add(p);         // set the size of frame        f.setSize(400, 400);         f.show();    }}
Output:  
Output:  
 Program to apply soft bevel border with specified colors to highlight and shadow: To create a soft bevel border, we first create a JPanel object p, all the borders will be applied to this object. The JPanel will be hosted inside the JFrame f. To set the bevel border, we create 2 JLabel objects, “l” and “l1”. The borders are applied by the function l.setBorder() and l1.setBorder(). To make the border soft, we call the constructor in the parameter of setBorder() method, which is indicated by line “new SoftBevelBorder()). And the colors are passed into these constructors as parameters, for ex: Color.red etc.). Finally, the borders are added to the JPanel by p.add() function and the results are shown by f.show(). 
 
Program to apply soft bevel border with specified colors to highlight and shadow: To create a soft bevel border, we first create a JPanel object p, all the borders will be applied to this object. The JPanel will be hosted inside the JFrame f. To set the bevel border, we create 2 JLabel objects, “l” and “l1”. The borders are applied by the function l.setBorder() and l1.setBorder(). To make the border soft, we call the constructor in the parameter of setBorder() method, which is indicated by line “new SoftBevelBorder()). And the colors are passed into these constructors as parameters, for ex: Color.red etc.). Finally, the borders are added to the JPanel by p.add() function and the results are shown by f.show(). 
Java
// Java Program to  apply soft bevel border with// specified colors to highlight and shadowimport java.awt.event.*;import java.awt.*;import javax.swing.*;import javax.swing.border.*;class bevel3 extends JFrame {     // frame    static JFrame f;     // main class    public static void main(String[] args)    {        // create a new frame        f = new JFrame("frame");         // create a object        bevel3 s = new bevel3();         // create a panel        JPanel p = new JPanel();         // create a label        JLabel l = new JLabel(" this is bevel border of raised type");         // create a label        JLabel l1 = new JLabel(" this is bevel border of lowered type");         // set border for panel        l.setBorder(new SoftBevelBorder(BevelBorder.RAISED, Color.red,                                                         Color.blue));         // set border for label        l1.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, Color.black,                                    Color.red, Color.pink, Color.yellow));         // add button to panel        p.add(l1);        p.add(l);         f.add(p);         // set the size of frame        f.setSize(400, 400);         f.show();    }}
Output:  
Output:  
Note: The above programs might not run in an online IDE please use an offline compile.Reference:  
https://docs.oracle.com/javase/7/docs/api/javax/swing/border/BevelBorder.html
https://docs.oracle.com/javase/7/docs/api/javax/swing/border/SoftBevelBorder.html
 
Akanksha_Rai
ManasChhabra2
sweetyty
java-swing
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Initialize an ArrayList in Java
Object Oriented Programming (OOPs) Concept in Java
HashMap in Java with Examples
Interfaces in Java
ArrayList in Java
How to iterate any Map in Java
Multidimensional Arrays in Java
Stack Class in Java
Stream In Java
Singleton Class in Java