Java 程序来在 Swing 中向面板添加标题边框
要为面板设置标题边框,让我们首先为我们的 Java Swing 应用程序创建一个面板
JPanel panel = new Jpanel(new BorderLayout());
现在,设置标题边框
panel.setBorder(new TitledBorder("Displaying Titled Border"));
以下是一个在 Swing 中向面板添加标题边框的示例
示例
import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.border.TitledBorder; public class SwingDemo { public static void main(String[] args) { JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(new TitledBorder("Displaying Titled Border")); panel.add(new JButton("Demo Button"), BorderLayout.SOUTH); JOptionPane.showMessageDialog(null, panel); } }
输出
广告