How to set border color for SoftBevelBorder in Java?


To set the border color for SoftBevelBorder in Java, use the Color class and set the color while creating the border −

SoftBevelBorder border = new SoftBevelBorder(
   BevelBorder.RAISED, Color.ORANGE, Color.ORANGE.darker(), Color.BLUE, Color.magenta.brighter());

We have set the following colors above as parameters −

highlightOuterColor: color to use for the bevel outer highlight
highlightInnerColor : color to use for the bevel inner highlight
shadowOuterColor : color to use for the bevel outer shadow
shadowInnerColor : color to use for the bevel inner shadow

The following is an example to set border color for SoftBevelBorde in Java −

Example

package my;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.BevelBorder;
import javax.swing.border.SoftBevelBorder;
public class SwingDemo {
   public static void main(String args[]) {
      JFrame frame = new JFrame("Demo");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      SoftBevelBorder border = new SoftBevelBorder(
         BevelBorder.RAISED, Color.ORANGE, Color.ORANGE.darker(),
      Color.BLUE, Color.magenta.brighter());
      JLabel label = new JLabel("This is a demo label with Soft Bevel Border");
      label.setBorder(border);
      Container contentPane = frame.getContentPane();
      contentPane.add(label, BorderLayout.CENTER);
      frame.setSize(550, 300);
      frame.setVisible(true);
   }
}

Output

Updated on: 30-Jul-2019

208 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements