Tutorialspoint

1 Answer
Chandu yadav

The matte border gives a “matte” look. Let’s say the following is our component −

JLabel label;
label = new JLabel("This has matte border!");

Let us create a matte border with BorderFactory class. Here, we have given color YELLOW using the Color class −

label.setBorder(BorderFactory.createMatteBorder(3, 5, 10, 5, Color.YELLOW));

The following is an example to create a Matte-look border −

Example

package my;
import javax.swing.BorderFactory;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class SwingDemo {
   public static void main(String[] args) throws Exception {
      JFrame frame = new JFrame("Demo");
      JLabel label;
      label = new JLabel("This has matte border!");
      label.setFont(new Font("Arial", Font.BOLD, 18));
      label.setVerticalAlignment(JLabel.CENTER);
      label.setBorder(BorderFactory.createMatteBorder(3, 5, 10, 5, Color.YELLOW));
      frame.add(label);
      frame.setSize(550,350);
      frame.setVisible(true);
   }
}

Output

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.