- 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 change Button Border in Java Swing
For Button border, use createLineBorder() method in Java, which allows you to set the color of the Border as well:
JButton button = new JButton("Demo Button!"); Border border = BorderFactory.createLineBorder(Color.BLUE);
The following is an example to change button border in Java:
Example
import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.border.Border; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Button Border"); Container container = frame.getContentPane(); JButton button = new JButton("Demo Button!"); Border border = BorderFactory.createLineBorder(Color.BLUE); button.setBorder(border); container.add(button, BorderLayout.CENTER); frame.setSize(550, 300); frame.setVisible(true); } }
Output
- Related Articles
- Java Program to use Soft Bevel Border in Swing
- Java Program to add Titled Border to Panel in Swing
- How to change font size with HTML in Java Swing JEditorPane?
- Can we change the Cursor with Java Swing?
- How to maximize JFrame in Java Swing
- How to make a canvas in Java Swing?
- How to add JTable to Panel in Java Swing?
- How to display row count in Java Swing JList
- How to leave space with EmptyBorder in Java Swing
- How to add a colored border to a button with CSS?
- How to add a title to JTable in Java Swing?
- How to change button label in alert box using JavaScript?
- How to change button label in confirm box using JavaScript?
- How to change color of Button in Android when Clicked?
- How to change the color of ttk button in Tkinter?

Advertisements