Open In App

Java Swing | BevelBorder and SoftBevelBorder

Improve
Improve
Like Article
Like
Save
Share
Report

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
 

  1. 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.
  2. BevelBorder(int Type, Color h, Color s):Creates a bevel border with the specified type, highlight and shadow colors.
  3. 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
 

  1. 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.
  2. SoftBevelBorder(int Type, Color h, Color s): Creates a bevel border with the specified type, highlight and shadow colors.
  3. 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: 

 

method explanation
getBevelType() returns the type of bevel border
getBorderInsets(Component c, Insets insets) Reinitialize the insets parameter with this Border’s current Insets.
getHighlightInnerColor() Returns the inner highlight color of the bevel border.
getHighlightInnerColor(Component c) Returns the inner highlight color of the bevel border when rendered on the specified component.
getHighlightOuterColor() Returns the outer highlight color of the bevel border.
getHighlightOuterColor(Component c) Returns the outer highlight color of the bevel border when rendered on the specified component.
getShadowInnerColor() Returns the inner shadow color of the bevel border.
getShadowInnerColor(Component c) Returns the inner shadow color of the bevel border when rendered on the specified component.
getShadowOuterColor() Returns the outer shadow color of the bevel border.
getShadowOuterColor(Component c) Returns the outer shadow color of the bevel border when rendered on the specified component.
isBorderOpaque() returns whether border is opaque or not

Below programs illustrate the Bevel Border class: 
 

  1. 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 type
import 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();
    }
}


  1. Output
     

  1.  
  2. 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 shadow
import 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();
    }
}


  1. Output
     

Below programs illustrate the SoftBevelBorder class: 
 

  1. 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 type
import 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();
    }
}


  1. Output
     

  1.  
  2. 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 shadow
import 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();
    }
}


  1. Output: 
     

Note: The above programs might not run in an online IDE please use an offline compile.
Reference
 

 



Last Updated : 16 Apr, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads