如何使用 Java 中的純色建立磨砂外觀邊框?
磨砂邊框呈現“磨砂”外觀。假設以下是我們元件 −
JLabel label; label = new JLabel("This has matte border!");
讓我們使用 BorderFactory 類建立一個磨砂邊框。此處,我們使用 Color 類給出了顏色 YELLOW −
label.setBorder(BorderFactory.createMatteBorder(3, 5, 10, 5, Color.YELLOW));
以下是一個建立磨砂外觀邊框的示例 −
示例
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); } }
輸出
廣告