如何在 Java 中为组件设置加高和降低 SoftBevelBorder。同时设置边框颜色。


让我们看看如何设置加高的 SoftBevelBorder −

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

让我们看看如何设置降低的 SoftBevelBorder −

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

下面是使用 Java 为组件设置加高和降低 SoftBevelBorder 的示例 −

示例

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);
   }
}

输出


更新于:30-7 月-2019

97 次浏览

启动您的 事业

通过完成课程获得认证

开始
广告