- 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 Line Border color and width with Java?
To set Line Border color and width, use the LineBorder. At first, set a panel wherein we need to set the line border −
JPanel panel = new JPanel();
Now, create a border and set on the panel created above −
Border border = new LineBorder(Color.ORANGE, 4, true); panel.setBorder(border);
The following is an example to set LineBorder color and width −
package my; import java.awt.Color; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.border.Border; import javax.swing.border.LineBorder; public class SwingDemo { public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); Border border = new LineBorder(Color.ORANGE, 4, true); panel.setBorder(border); String[][] rec = { { "1", "Steve", "AUS" }, { "2", "Virat", "IND" }, { "3", "Kane", "NZ" }, { "4", "David", "AUS" }, { "5", "Ben", "ENG" }, { "6", "Eion", "ENG" }, }; String[] header = { "Rank", "Player", "Country" }; JTable table = new JTable(rec, header); table.setShowHorizontalLines(true); table.setGridColor(Color.orange); table.setCellSelectionEnabled(true); panel.add(new JScrollPane(table)); frame.add(panel); frame.setSize(550, 400); frame.setVisible(true); } }
Output
- Related Articles
- How to set border width, border style, and border color in one declaration with JavaScript?
- Set border width with CSS
- How to set border color for SoftBevelBorder in Java?
- Set the border image width with CSS
- How to set the width of the right border with JavaScript?
- How to set the width of the left border with JavaScript?
- How to set the width of the bottom border with JavaScript?
- How to set the width of the top border with JavaScript?
- How to set raised and lowered SoftBevelBorder for components in Java. Also set the border color.
- How to set the color of the top border with JavaScript?
- How to set the color of an elements border with JavaScript?
- How to set the color of the right border with JavaScript?
- How to set the color of the left border with JavaScript?
- Set the width of image border with CSS
- Set the color of the border with CSS

Advertisements