如何使用 Java 中的 BorderFactory 类为组件创建蚀刻边框?
蚀刻边框呈现“蚀刻”外观。假设以下内容是我们的组件 −
JLabel label; label = new JLabel("This has etched border with an 'etched' look!");
让我们使用 BorderFactory 类创建蚀刻边框 −
label.setBorder(BorderFactory.createEtchedBorder());
以下是一个使用 BorderFactory 类为组件创建蚀刻边框的示例 −
示例
package my; import javax.swing.BorderFactory; 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 etched border with an 'etched' look!"); label.setFont(new Font("Arial", Font.BOLD, 18)); label.setVerticalAlignment(JLabel.CENTER); label.setBorder(BorderFactory.createEtchedBorder()); frame.add(label); frame.setSize(550,350); frame.setVisible(true); } }
输出
广告