Java Swing | BevelBorder and SoftBevelBorder

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 explanantion
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().
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // 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 boreder for panel
            l.setBorder(new BevelBorder(BevelBorder.RAISED));
      
            // set boreder 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();
        }
    }

    chevron_right

    
    

    Output:

  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().
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // 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 boreder for panel
            l.setBorder(new BevelBorder(BevelBorder.RAISED, Color.red,
                                                           Color.blue));
      
            // set boreder 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();
        }
    }

    chevron_right

    
    

    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().
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // 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();
        }
    }

    chevron_right

    
    

    Output:

  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().
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // 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 boreder for panel
            l.setBorder(new SoftBevelBorder(BevelBorder.RAISED, Color.red,
                                                             Color.blue));
      
            // set boreder 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();
        }
    }

    chevron_right

    
    

    Output:

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

Reference:



My Personal Notes arrow_drop_up

Second year Department of Information Technology Jadavpur University

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : Akanksha_Rai



Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.