NiallMitch14
NiallMitch14

Reputation: 1229

Set Border Thickness on JPanels?

I'm wondering if it is possible to adjust the thickness of a border around a JPanel in Java? I currently have a border defined and the JPanel adds the border around it but I would like it to be a little thicker:

Border border;
JPanel panel;

border = BorderFactory.creatLineBorder(Color.RED);
panel = new JPanel();
panel.setBorder(border);

Upvotes: 6

Views: 17274

Answers (3)

Jean-François Savard
Jean-François Savard

Reputation: 21004

I believe you could use BorderFactory

panel.setBorder(BorderFactory.createStrokeBorder(new BasicStroke(5.0f)));

See

Upvotes: 7

Muhammad Nasir Zafar
Muhammad Nasir Zafar

Reputation: 21

JPanel panel1=new JPanel();
 panel1.setBounds(0,0,201,201);
 panel1.setBorder(BorderFactory.createLineBorder(Color.BLUE,3));

Note:Here border thickness is 3 and color is blue.

Upvotes: 2

copeg
copeg

Reputation: 8348

BorderFactory has a method that accepts two parameters - the Color and thickness

border = BorderFactory.creatLineBorder(Color.RED, thickness);

Alternatively, you can use the LineBorder class to generate a thicker line border

LineBorder border = new LineBorder(Color.RED, thickness)
panel.setBorder(border);

Upvotes: 5

Related Questions