- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set a MatteBorder from BorderFactory in Java?
Set a MatteBorder from BorderFactory class −
MatteBorder border = (MatteBorder)BorderFactory.createMatteBorder(2, -1, 5, 10, icon);
Now, set the above created MatteBorder to a component −
JButton button = new JButton("Matte Border"); button.setBorder(border);
The following is an example to set a MatteBorder from BorderFactory class −
Example
package my; import java.awt.BorderLayout; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.border.Border; import javax.swing.border.EtchedBorder; import javax.swing.border.MatteBorder; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border raisedBorder = new EtchedBorder(EtchedBorder.RAISED); ImageIcon icon = new ImageIcon("new.gif"); MatteBorder border = (MatteBorder)BorderFactory.createMatteBorder(2, -1, 5, 10, icon); JButton raisedButton = new JButton("Raised Border"); raisedButton.setBorder(raisedBorder); JButton button = new JButton("Matte Border"); button.setBorder(border); Container contentPane = frame.getContentPane(); contentPane.add(raisedButton,BorderLayout.NORTH); contentPane.add(button,BorderLayout.EAST); frame.setSize(600, 300); frame.setVisible(true); } }
Output
- Related Articles
- How to set color to MatteBorder in Java?
- How can I set an EtchedBorder from BorderFactory class to a component in Java?
- How to create and set an Empty Border from BorderFactory class in Java?
- How to create a LineBorder with BorderFactory class in Java?
- How to create etched border for a component using BorderFactory class in Java?
- Create empty border with BorderFactory class in Java?
- How can we implement different borders using the BorderFactory in Java?\n
- Java Program to remove all elements from a set in Java
- How do you create a list from a set in Java?
- How can we set the orientation of a JTextArea from right to left in Java?
- How to set path in Java?
- How to set JCheckBoxMenuItem for a MenuItem in Java?
- Java program to remove items from Set
- How to convert an Array to a Set in Java?
- How to convert a Java list to a set?

Advertisements