How to set raised and lowered SoftBevelBorder for components in Java. Also set the border color.

Java 8Object Oriented ProgrammingProgramming

Let us see how to set the raised SoftBevelBorder −

Border raisedBorder = new SoftBevelBorder(
   SoftBevelBorder.RAISED, Color.GREEN, Color.GREEN.darker(),Color.MAGENTA, Color.magenta.brighter());

Let us see how to set the lowered SoftBevelBorder −

Border loweredBorder = new SoftBevelBorder(
   SoftBevelBorder.LOWERED, Color.ORANGE, Color.YELLOW.darker(), Color.BLUE, Color.yellow.brighter());

The following is an example to set raised and lowered SoftBevelBorder for components in Java −

Example

package my;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.Border;
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);
      Border raisedBorder = new SoftBevelBorder(
         SoftBevelBorder.RAISED, Color.GREEN, Color.GREEN.darker(),
      Color.MAGENTA, Color.magenta.brighter());
      Border raisedBorder2 = new SoftBevelBorder(SoftBevelBorder.RAISED);
      Border loweredBorder = new SoftBevelBorder(
         SoftBevelBorder.LOWERED, Color.ORANGE, Color.YELLOW.darker(),
      Color.BLUE, Color.yellow.brighter());
      JButton raisedButton = new JButton("Raised");
      raisedButton.setBorder(raisedBorder);
      JButton loweredButton = new JButton("Lowered");
      loweredButton.setBorder(loweredBorder);
      JLabel raisedLabel = new JLabel("Raised");
      raisedLabel.setBorder(raisedBorder2);
      Container contentPane = frame.getContentPane();
      contentPane.add(raisedButton,BorderLayout.WEST);
      contentPane.add(loweredButton,BorderLayout.EAST);
      contentPane.add(raisedLabel,BorderLayout.CENTER);
      frame.setSize(550, 300);
      frame.setVisible(true);
   }
}

Output


raja
Published on 06-Jun-2019 13:36:49
Advertisements