How to Create a Bevel Border in Java
Submitted by donbermoy on Monday, December 8, 2014 - 18:12.
This tutorial will teach you how to create a bevel border in java. A Bevel Border is an opaque border that draws a border with a three-dimensional appearance; raised or lowered.
So, now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of bevelBorder.java.
2. Import the following packages:
3. Initialize your variable in your Main, variable frame for JFrame, variable button1 and variable button2 as JButton.
Now, we will create again another Bevel Border which is lowered. We will just used the constant LOWERED in the BevelBorder. In the lowered bevel border, the first color will be in the bottom and the second one will be on the top.
Then, we will add the two borders(the raised and lowered bevel borders) to the two buttons.
5. Now, we will have its layout into Grid Layout using the setLayout method of the frame.
Then add the buttons into the frame using the add method. Lastly, set the size, visibility, and the close operation of the frame. Have this code below:
Output:
Here's the full code of this tutorial:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
- import java.awt.*; //used to access the Color class and the GridLayout
- import javax.swing.*; //used to access the JFrame, JButton, and BorderFactory class
- import javax.swing.border.*; //used to access the BevelBorder and Border subclass of the border class library in swing
4. First, we will create a Raised Bevel Border with the use of the Border class. We will name it as RaisedBorder and with the use of the BorderFactory class with its createBevelBorder method, we can now create a bevel border. If we declare it as Raised, the first color will be in your top, and the second will be the color in the bottom.
- Border LoweredBorder = BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.GREEN, Color.CYAN);
- button1.setBorder(RaisedBorder);
- button2.setBorder(LoweredBorder);
- frame.getContentPane().add(button1);
- frame.getContentPane().add(button2);
- frame.setSize(300, 100);
- frame.setVisible(true);

- import java.awt.*; //used to access the Color class and the GridLayout
- import javax.swing.*; //used to access the JFrame, JButton, and BorderFactory class
- import javax.swing.border.*; //used to access the BevelBorder and Border subclass of the border class library in swing
- public class bevelBorder {
- Border LoweredBorder = BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.GREEN, Color.CYAN);
- button1.setBorder(RaisedBorder);
- button2.setBorder(LoweredBorder);
- frame.getContentPane().add(button1);
- frame.getContentPane().add(button2);
- frame.setSize(300, 100);
- frame.setVisible(true);
- }
- }
Add new comment
- 249 views