How to Create an Etched Border in Java
Submitted by donbermoy on Tuesday, December 9, 2014 - 18:40.
This tutorial will teach you how to create an etched border in Java. An etched border has an etched-in or etched-out effect and in default it is in etched-in effect. Like bevel borders, it has also constants of raised and lowered etched.
So, now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of etchedBorder.java.
2. Import the following package library:
3. We will initialize variables in our Main, variable frame as JFrame and button1 labeled "Normal Etched",button2 labeled "Raised Etched", and button3 labeled "Lowered Etched" as JButton.
Then we will create another etched border and will named it as raisedBorder because it will have an etched of raised, color red, and color blue. This border will set to the button2.
Lastly, we will create another etched border and will named it as loweredBorder because it will have an etched lowered, color yellow, and color green. This border will set to the button3.
5. Now, we will have its layout into Grid Layout using the setLayout method of the frame.
Add all the buttons to 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 GridLayout and Color class
- import javax.swing.*; //used to access the JFrame and JButton class
- import javax.swing.border.*; //used to access the Border and EtchedBorder class
4. Now, we will create an etched border for button1 and we will use the Border class here with the EtchedBorder class instantiation. We will name the Border as normalBorder.
- button1.setBorder(normalBorder);
- button2.setBorder(raisedBorder);
- button3.setBorder(loweredBorder);
- frame.getContentPane().add(button1 );
- frame.getContentPane().add(button2);
- frame.getContentPane().add(button3);
- frame.setSize(350, 200);
- frame.setVisible(true);
- import java.awt.*; //used to access the GridLayout and Color class
- import javax.swing.*; //used to access the JFrame and JButton class
- import javax.swing.border.*; //used to access the Border and EtchedBorder class
- public class etchedBorder {
- button1.setBorder(normalBorder);
- button2.setBorder(raisedBorder);
- button3.setBorder(loweredBorder);
- frame.getContentPane().add(button1 );
- frame.getContentPane().add(button2);
- frame.getContentPane().add(button3);
- frame.setSize(350, 200);
- frame.setVisible(true);
- }
- }
Add new comment
- 130 views