How to set border color for SoftBevelBorder in Java?

Java 8Object Oriented ProgrammingProgramming

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

raja
Published on 06-Jun-2019 10:02:34
Advertisements